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

Disable TransformSubnetTx post-Etna #3152

Merged
merged 14 commits into from
Aug 5, 2024
11 changes: 8 additions & 3 deletions vms/platformvm/txs/executor/standard_tx_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
var (
_ txs.Visitor = (*StandardTxExecutor)(nil)

errEmptyNodeID = errors.New("validator nodeID cannot be empty")
errMaxStakeDurationTooLarge = errors.New("max stake duration must be less than or equal to the global max stake duration")
errMissingStartTimePreDurango = errors.New("staker transactions must have a StartTime pre-Durango")
errEmptyNodeID = errors.New("validator nodeID cannot be empty")
errMaxStakeDurationTooLarge = errors.New("max stake duration must be less than or equal to the global max stake duration")
errMissingStartTimePreDurango = errors.New("staker transactions must have a StartTime pre-Durango")
errTransformSubnetTxPostEUpgrade = errors.New("TransformSubnetTx is not permitted post-EUpgrade")
)

type StandardTxExecutor struct {
Expand Down Expand Up @@ -436,6 +437,10 @@ func (e *StandardTxExecutor) TransformSubnetTx(tx *txs.TransformSubnetTx) error
return err
}

if e.Config.UpgradeConfig.IsEActivated(currentTimestamp) {
dhrubabasu marked this conversation as resolved.
Show resolved Hide resolved
return errTransformSubnetTxPostEUpgrade
}

// Note: math.MaxInt32 * time.Second < math.MaxInt64 - so this can never
// overflow.
if time.Duration(tx.MaxStakeDuration)*time.Second > e.Backend.Config.MaxStakeDuration {
Expand Down
48 changes: 48 additions & 0 deletions vms/platformvm/txs/executor/standard_tx_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,54 @@ func TestDurangoMemoField(t *testing.T) {
}
}

// Verifies that [TransformSubnetTx] are disabled post-E
func TestEUpgradeDisabledTransactions(t *testing.T) {
abi87 marked this conversation as resolved.
Show resolved Hide resolved
type test struct {
name string
buildTx func(*environment) *txs.Tx
expectedErr error
}

tests := []test{
marun marked this conversation as resolved.
Show resolved Hide resolved
{
name: "TransformSubnetTx",
buildTx: func(_ *environment) *txs.Tx {
// This is a hacky way of getting a TransformSubnetTx to pass
// SyntacticVerify()
utx := &txs.TransformSubnetTx{}
utx.SyntacticallyVerified = true
return &txs.Tx{
Unsigned: utx,
TxID: ids.GenerateTestID(),
}
},
expectedErr: errTransformSubnetTxPostEUpgrade,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)

env := newEnvironment(t, eUpgrade)
env.ctx.Lock.Lock()
defer env.ctx.Lock.Unlock()

onAcceptState, err := state.NewDiff(env.state.GetLastAccepted(), env)
require.NoError(err)

tx := tt.buildTx(env)

err = tx.Unsigned.Visit(&StandardTxExecutor{
Backend: &env.backend,
State: onAcceptState,
Tx: tx,
})
require.ErrorIs(err, tt.expectedErr)
})
}
}

// Returns a RemoveSubnetValidatorTx that passes syntactic verification.
// Memo field is empty as required post Durango activation
func newRemoveSubnetValidatorTx(t *testing.T) (*txs.RemoveSubnetValidatorTx, *txs.Tx) {
Expand Down
Loading