Skip to content

Commit

Permalink
Merge pull request #2112 from OffchainLabs/arbos-scheduled-upgrade-ge…
Browse files Browse the repository at this point in the history
…tter

Add ArbOS precompile method to get scheduled upgrade
  • Loading branch information
PlasmaPower authored Jan 29, 2024
2 parents 18fe0d4 + 7bc1412 commit 3cb5f77
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts
13 changes: 13 additions & 0 deletions precompiles/ArbOwnerPublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ func (con ArbOwnerPublic) GetInfraFeeAccount(c ctx, evm mech) (addr, error) {
func (con ArbOwnerPublic) GetBrotliCompressionLevel(c ctx, evm mech) (uint64, error) {
return c.State.BrotliCompressionLevel()
}

// GetScheduledUpgrade gets the next scheduled ArbOS version upgrade and its activation timestamp.
// Returns (0, 0, nil) if no ArbOS upgrade is scheduled.
func (con ArbOwnerPublic) GetScheduledUpgrade(c ctx, evm mech) (uint64, uint64, error) {
version, timestamp, err := c.State.GetScheduledUpgrade()
if err != nil {
return 0, 0, err
}
if c.State.ArbOSVersion() >= version {
return 0, 0, nil
}
return version, timestamp, nil
}
51 changes: 51 additions & 0 deletions system_tests/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,54 @@ func TestPrecompileErrorGasLeft(t *testing.T) {
Require(t, err)
assertNotAllGasConsumed(common.HexToAddress("0xff"), arbDebug.Methods["legacyError"].ID)
}

func TestScheduleArbosUpgrade(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
cleanup := builder.Build(t)
defer cleanup()

auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)

arbOwnerPublic, err := precompilesgen.NewArbOwnerPublic(common.HexToAddress("0x6b"), builder.L2.Client)
Require(t, err, "could not bind ArbOwner contract")

arbOwner, err := precompilesgen.NewArbOwner(common.HexToAddress("0x70"), builder.L2.Client)
Require(t, err, "could not bind ArbOwner contract")

callOpts := &bind.CallOpts{Context: ctx}
scheduled, err := arbOwnerPublic.GetScheduledUpgrade(callOpts)
Require(t, err, "failed to call GetScheduledUpgrade before scheduling upgrade")
if scheduled.ArbosVersion != 0 || scheduled.ScheduledForTimestamp != 0 {
t.Errorf("expected no upgrade to be scheduled, got version %v timestamp %v", scheduled.ArbosVersion, scheduled.ScheduledForTimestamp)
}

// Schedule a noop upgrade, which should test GetScheduledUpgrade in the same way an already completed upgrade would.
tx, err := arbOwner.ScheduleArbOSUpgrade(&auth, 1, 1)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

scheduled, err = arbOwnerPublic.GetScheduledUpgrade(callOpts)
Require(t, err, "failed to call GetScheduledUpgrade after scheduling noop upgrade")
if scheduled.ArbosVersion != 0 || scheduled.ScheduledForTimestamp != 0 {
t.Errorf("expected completed scheduled upgrade to be ignored, got version %v timestamp %v", scheduled.ArbosVersion, scheduled.ScheduledForTimestamp)
}

// TODO: Once we have an ArbOS 30, test a real upgrade with it
// We can't test 11 -> 20 because 11 doesn't have the GetScheduledUpgrade method we want to test
var testVersion uint64 = 100
var testTimestamp uint64 = 1 << 62
tx, err = arbOwner.ScheduleArbOSUpgrade(&auth, 100, 1<<62)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

scheduled, err = arbOwnerPublic.GetScheduledUpgrade(callOpts)
Require(t, err, "failed to call GetScheduledUpgrade after scheduling upgrade")
if scheduled.ArbosVersion != testVersion || scheduled.ScheduledForTimestamp != testTimestamp {
t.Errorf("expected upgrade to be scheduled for version %v timestamp %v, got version %v timestamp %v", testVersion, testTimestamp, scheduled.ArbosVersion, scheduled.ScheduledForTimestamp)
}
}

0 comments on commit 3cb5f77

Please sign in to comment.