Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ValidateRewardProtocol flag #3946

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ type (
CorrectTxLogIndex bool
RevertLog bool
TolerateLegacyAddress bool
ValidateRewardProtocol bool
CreateLegacyNonceAccount bool
FixGasAndNonceUpdate bool
FixUnproductiveDelegates bool
Expand Down Expand Up @@ -244,7 +243,6 @@ func WithFeatureCtx(ctx context.Context) context.Context {
CorrectTxLogIndex: g.IsMidway(height),
RevertLog: g.IsMidway(height),
TolerateLegacyAddress: !g.IsNewfoundland(height),
ValidateRewardProtocol: g.IsNewfoundland(height),
CreateLegacyNonceAccount: !g.IsOkhotsk(height),
FixGasAndNonceUpdate: g.IsOkhotsk(height),
FixUnproductiveDelegates: g.IsOkhotsk(height),
Expand Down
3 changes: 0 additions & 3 deletions action/protocol/rewarding/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ func createGrantRewardAction(rewardType int, height uint64) action.Envelope {

// Validate validates a reward action
func (p *Protocol) Validate(ctx context.Context, act action.Action, sr protocol.StateReader) error {
if !protocol.MustGetFeatureCtx(ctx).ValidateRewardProtocol {
return nil
}
envestcc marked this conversation as resolved.
Show resolved Hide resolved
switch act.(type) {
case *action.GrantReward:
actionCtx := protocol.MustGetActionCtx(ctx)
Expand Down
35 changes: 22 additions & 13 deletions state/factory/workingset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,11 @@ func TestWorkingSet_ValidateBlock_SystemAction(t *testing.T) {
require.NoError(f2.Stop(ctx))
}()

zctx := protocol.WithBlockCtx(context.Background(),
protocol.BlockCtx{
BlockHeight: uint64(1),
Producer: identityset.Address(27),
GasLimit: testutil.TestGasLimit * 100000,
})
zctx = genesis.WithGenesisContext(zctx, cfg.Genesis)
zctx := protocol.WithBlockCtx(ctx, protocol.BlockCtx{
BlockHeight: uint64(1),
Producer: identityset.Address(28),
GasLimit: testutil.TestGasLimit * 100000,
})
zctx = protocol.WithFeatureCtx(protocol.WithBlockchainCtx(zctx, protocol.BlockchainCtx{
ChainID: 1,
}))
Expand All @@ -305,7 +303,7 @@ func TestWorkingSet_ValidateBlock_SystemAction(t *testing.T) {
require.NoError(err)
receiptRoot, err := hash.HexStringToHash256("f04673451e31386a8fddfcf7750665bfcf33f239f6c4919430bb11a144e1aa95")
require.NoError(err)
actions := []action.SealedEnvelope{makeRewardAction(t), makeTransferAction(t, 1)}
actions := []action.SealedEnvelope{makeRewardAction(t, 28), makeTransferAction(t, 1)}
for _, f := range factories {
block := makeBlock(t, hash.ZeroHash256, receiptRoot, digestHash, actions...)
require.ErrorIs(f.Validate(zctx, block), errInvalidSystemActionLayout)
Expand All @@ -316,18 +314,29 @@ func TestWorkingSet_ValidateBlock_SystemAction(t *testing.T) {
require.NoError(err)
receiptRoot, err := hash.HexStringToHash256("a59bd06fe4d2bb537895f170dec1f9213045cb13480e4941f1abdc8d13b16fae")
require.NoError(err)
actions := []action.SealedEnvelope{makeTransferAction(t, 1), makeRewardAction(t)}
actions := []action.SealedEnvelope{makeTransferAction(t, 1), makeRewardAction(t, 28)}
for _, f := range factories {
block := makeBlock(t, hash.ZeroHash256, receiptRoot, digestHash, actions...)
require.ErrorIs(f.Validate(zctx, block), nil)
}
})
t.Run("wrong reward action signer", func(t *testing.T) {
digestHash, err := hash.HexStringToHash256("ade24a5c647b5af34c4e74fe0d8f1fa410f6fb115f8fc2d39e45ca2f895de9ca")
require.NoError(err)
receiptRoot, err := hash.HexStringToHash256("a59bd06fe4d2bb537895f170dec1f9213045cb13480e4941f1abdc8d13b16fae")
require.NoError(err)
actions := []action.SealedEnvelope{makeTransferAction(t, 1), makeRewardAction(t, 27)}
for _, f := range factories {
block := makeBlock(t, hash.ZeroHash256, receiptRoot, digestHash, actions...)
require.ErrorContains(f.Validate(zctx, block), "Only producer could create reward")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a positive test to trigger the error

}
})
t.Run("postiche system action", func(t *testing.T) {
digestHash, err := hash.HexStringToHash256("ade24a5c647b5af34c4e74fe0d8f1fa410f6fb115f8fc2d39e45ca2f895de9ca")
require.NoError(err)
receiptRoot, err := hash.HexStringToHash256("a59bd06fe4d2bb537895f170dec1f9213045cb13480e4941f1abdc8d13b16fae")
require.NoError(err)
actions := []action.SealedEnvelope{makeTransferAction(t, 1), makeRewardAction(t), makeRewardAction(t)}
actions := []action.SealedEnvelope{makeTransferAction(t, 1), makeRewardAction(t, 28), makeRewardAction(t, 28)}
for _, f := range factories {
block := makeBlock(t, hash.ZeroHash256, receiptRoot, digestHash, actions...)
require.ErrorIs(f.Validate(zctx, block), errInvalidSystemActionLayout)
Expand All @@ -338,7 +347,7 @@ func TestWorkingSet_ValidateBlock_SystemAction(t *testing.T) {
require.NoError(err)
receiptRoot, err := hash.HexStringToHash256("f04673451e31386a8fddfcf7750665bfcf33f239f6c4919430bb11a144e1aa95")
require.NoError(err)
rewardAct := makeRewardAction(t)
rewardAct := makeRewardAction(t, 28)
rewardAct.SetNonce(2)
actions := []action.SealedEnvelope{makeTransferAction(t, 1), rewardAct}
for _, f := range factories {
Expand Down Expand Up @@ -372,7 +381,7 @@ func makeTransferAction(t *testing.T, nonce uint64) action.SealedEnvelope {
return sevlp
}

func makeRewardAction(t *testing.T) action.SealedEnvelope {
func makeRewardAction(t *testing.T, signer int) action.SealedEnvelope {
gb := action.GrantRewardBuilder{}
grant := gb.SetRewardType(action.BlockReward).SetHeight(1).Build()
eb2 := action.EnvelopeBuilder{}
Expand All @@ -381,7 +390,7 @@ func makeRewardAction(t *testing.T) action.SealedEnvelope {
SetGasLimit(grant.GasLimit()).
SetAction(&grant).
Build()
sevlp, err := action.Sign(evlp, identityset.PrivateKey(28))
sevlp, err := action.Sign(evlp, identityset.PrivateKey(signer))
require.NoError(t, err)
return sevlp
}
Expand Down