From a80fa288679b0f4145e477ffd54ef2af34ad0f99 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sun, 28 Jan 2024 16:53:47 -0700 Subject: [PATCH 1/4] Add ArbOS precompile method to get scheduled upgrade --- contracts | 2 +- precompiles/ArbOwnerPublic.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/contracts b/contracts index 7b84be56ec..6e61fdb475 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 7b84be56ec5352aaeb85c58fea7f50725e1927d9 +Subproject commit 6e61fdb475bb4b38870e40827dd37627afc4bacd diff --git a/precompiles/ArbOwnerPublic.go b/precompiles/ArbOwnerPublic.go index 4064f41bef..451e18e1cc 100644 --- a/precompiles/ArbOwnerPublic.go +++ b/precompiles/ArbOwnerPublic.go @@ -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 +} From 76924e06efc3a4292b36dcf489a9a86d7dbd44b9 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sun, 28 Jan 2024 16:58:19 -0700 Subject: [PATCH 2/4] Bump contracts pin --- contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts b/contracts index 6e61fdb475..9a6bfad236 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 6e61fdb475bb4b38870e40827dd37627afc4bacd +Subproject commit 9a6bfad2363322099d399698751551ff044c7a72 From 4db1014c0f0e5854177b4dc7c07e5c8b6380d870 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sun, 28 Jan 2024 17:06:51 -0700 Subject: [PATCH 3/4] Add test of scheduling upgrade and getting it --- system_tests/precompile_test.go | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/system_tests/precompile_test.go b/system_tests/precompile_test.go index 10db09275b..7040a956cb 100644 --- a/system_tests/precompile_test.go +++ b/system_tests/precompile_test.go @@ -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) + } +} From 7bc141282c4d81a2b7d41723a1f39046e9da2e39 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sun, 28 Jan 2024 17:10:04 -0700 Subject: [PATCH 4/4] Fix testTimestamp --- system_tests/precompile_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system_tests/precompile_test.go b/system_tests/precompile_test.go index 7040a956cb..e0a9c2ce78 100644 --- a/system_tests/precompile_test.go +++ b/system_tests/precompile_test.go @@ -159,8 +159,8 @@ func TestScheduleArbosUpgrade(t *testing.T) { // 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) + var testTimestamp uint64 = 1 << 62 + tx, err = arbOwner.ScheduleArbOSUpgrade(&auth, 100, 1<<62) Require(t, err) _, err = builder.L2.EnsureTxSucceeded(tx) Require(t, err)