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

[action] New MigrateStake Action #4299

Merged
merged 21 commits into from
Jun 19, 2024
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
3 changes: 3 additions & 0 deletions action/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ func newStakingActionFromABIBinary(data []byte) (actionPayload, error) {
if act, err := NewCandidateTransferOwnershipFromABIBinary(data); err == nil {
return act, nil
}
if act, err := NewMigrateStakeFromABIBinary(data); err == nil {
return act, nil
}
return nil, ErrInvalidABI
}

Expand Down
8 changes: 8 additions & 0 deletions action/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func (elp *envelope) Proto() *iotextypes.ActionCore {
actCore.Action = &iotextypes.ActionCore_CandidateTransferOwnership{CandidateTransferOwnership: act.Proto()}
case *txContainer:
actCore.Action = &iotextypes.ActionCore_TxContainer{TxContainer: act.proto()}
case *MigrateStake:
actCore.Action = &iotextypes.ActionCore_StakeMigrate{StakeMigrate: act.Proto()}
default:
log.S().Panicf("Cannot convert type of action %T.\r\n", act)
}
Expand Down Expand Up @@ -241,6 +243,12 @@ func (elp *envelope) LoadProto(pbAct *iotextypes.ActionCore) error {
return err
}
elp.payload = act
case pbAct.GetStakeMigrate() != nil:
act := &MigrateStake{}
if err := act.LoadProto(pbAct.GetStakeMigrate()); err != nil {
return err
}
elp.payload = act
default:
return errors.Errorf("no applicable action to handle proto type %T", pbAct.Action)
}
Expand Down
2 changes: 2 additions & 0 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type (
CandidateIdentifiedByOwner bool
UseTxContainer bool
LimitedStakingContract bool
MigrateNativeStake bool
}

// FeatureWithHeightCtx provides feature check functions.
Expand Down Expand Up @@ -273,6 +274,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
CandidateIdentifiedByOwner: !g.IsToBeEnabled(height),
UseTxContainer: g.IsToBeEnabled(height),
LimitedStakingContract: !g.IsToBeEnabled(height),
MigrateNativeStake: g.IsToBeEnabled(height),
},
)
}
Expand Down
13 changes: 7 additions & 6 deletions action/protocol/execution/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.

package execution
package execution_test
Copy link
Member

Choose a reason for hiding this comment

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

why need to change this

Copy link
Member Author

Choose a reason for hiding this comment

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

to solve import cycle issue between execution and staking


import (
"bytes"
Expand Down Expand Up @@ -33,6 +33,7 @@ import (
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/account"
accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util"
"github.com/iotexproject/iotex-core/action/protocol/execution"
"github.com/iotexproject/iotex-core/action/protocol/execution/evm"
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/action/protocol/rolldpos"
Expand Down Expand Up @@ -490,7 +491,7 @@ func (sct *SmartContractTest) prepareBlockchain(
r.NoError(reward.Register(registry))

r.NotNil(bc)
execution := NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
execution := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
r.NoError(execution.Register(registry))
r.NoError(bc.Start(ctx))

Expand Down Expand Up @@ -638,7 +639,7 @@ func (sct *SmartContractTest) run(r *require.Assertions) {

func TestProtocol_Validate(t *testing.T) {
require := require.New(t)
p := NewProtocol(func(uint64) (hash.Hash256, error) {
p := execution.NewProtocol(func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
}, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)

Expand All @@ -650,8 +651,8 @@ func TestProtocol_Validate(t *testing.T) {
}{
{"limit 32KB", 0, 32683, nil},
{"exceed 32KB", 0, 32684, action.ErrOversizedData},
{"limit 48KB", genesis.Default.SumatraBlockHeight, uint64(_executionSizeLimit48KB), nil},
{"exceed 48KB", genesis.Default.SumatraBlockHeight, uint64(_executionSizeLimit48KB) + 1, action.ErrOversizedData},
{"limit 48KB", genesis.Default.SumatraBlockHeight, uint64(48 * 1024), nil},
{"exceed 48KB", genesis.Default.SumatraBlockHeight, uint64(48*1024) + 1, action.ErrOversizedData},
}

for i := range cases {
Expand Down Expand Up @@ -733,7 +734,7 @@ func TestProtocol_Handle(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
exeProtocol := NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
exeProtocol := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
require.NoError(exeProtocol.Register(registry))
require.NoError(bc.Start(ctx))
require.NotNil(bc)
Expand Down
Loading
Loading