From 87517f00ae16877cff3dd96e8eb2aff6053d66ac Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Thu, 8 Jun 2023 23:39:58 -0400 Subject: [PATCH 01/28] test engine edit --- pkg/rpc/engine.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/rpc/engine.go b/pkg/rpc/engine.go index ce1e8638e..8a9adceaa 100644 --- a/pkg/rpc/engine.go +++ b/pkg/rpc/engine.go @@ -63,3 +63,18 @@ func (c *EngineClient) GetPayload( return result.ExecutionPayload, nil } + +func (c *EngineClient) ExchangeTransitionConfiguration( + ctx context.Context, + cfg *engine.TransitionConfigurationV1, +) (*engine.TransitionConfigurationV1, error) { + timeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + + var result *engine.TransitionConfigurationV1 + if err := c.Client.CallContext(timeoutCtx, &result, "engine_exchangeTransitionConfigurationV1", cfg); err != nil { + return nil, err + } + + return result, nil +} From 5381604af171e5b0d0cff809fff5c5f2552aab61 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Fri, 9 Jun 2023 03:16:00 -0400 Subject: [PATCH 02/28] rudimentary loop --- driver/driver.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/driver/driver.go b/driver/driver.go index d4e771d73..cfe550f24 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -2,13 +2,17 @@ package driver import ( "context" + "math/big" "sync" "time" "github.com/cenkalti/backoff/v4" + "github.com/ethereum/go-ethereum/beacon/engine" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" + "github.com/holiman/uint256" chainSyncer "github.com/taikoxyz/taiko-client/driver/chain_syncer" "github.com/taikoxyz/taiko-client/driver/state" "github.com/taikoxyz/taiko-client/pkg/rpc" @@ -103,6 +107,7 @@ func (d *Driver) Start() error { d.wg.Add(2) go d.eventLoop() go d.reportProtocolStatus() + go d.checkTransitionConfig() return nil } @@ -220,6 +225,39 @@ func (d *Driver) reportProtocolStatus() { } } +func (d *Driver) checkTransitionConfig() { + ticker := time.NewTicker(60 * time.Second) + defer func() { + ticker.Stop() + d.wg.Done() + }() + + for { + select { + case <-d.ctx.Done(): + return + case <-ticker.C: + i := new(big.Int) + i.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) + ttd := new(uint256.Int) + ttd.SetFromBig(i) + tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ + // TerminalTotalDifficulty: 115792089237316195423570985008687907853269984665640564039457584007913129638912, + // not sure how to convert uint256 to *hexutil.Big + TerminalBlockHash: common.Hash{}, + TerminalBlockNumber: 0, + }) + if err != nil { + log.Error("Failed to exchange Transition Configuration", "error", err) + continue + } + log.Info("exchanged transition config", + "transitionconfig", tc) + } + } + +} + // Name returns the application name. func (d *Driver) Name() string { return "driver" From 11fbcf305d21a8ca6f26834a356ea69fe25ed428 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Fri, 9 Jun 2023 03:24:23 -0400 Subject: [PATCH 03/28] fix lint --- driver/driver.go | 1 - 1 file changed, 1 deletion(-) diff --git a/driver/driver.go b/driver/driver.go index cfe550f24..6bac93542 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -255,7 +255,6 @@ func (d *Driver) checkTransitionConfig() { "transitionconfig", tc) } } - } // Name returns the application name. From a4bfc28e0f025223dc4235ae8f9888c19f01aabc Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Fri, 9 Jun 2023 17:05:14 -0400 Subject: [PATCH 04/28] add backoff --- driver/driver.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/driver/driver.go b/driver/driver.go index 6bac93542..129d5bff9 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -226,6 +226,11 @@ func (d *Driver) reportProtocolStatus() { } func (d *Driver) checkTransitionConfig() { + if d.ctx.Err() != nil { + log.Warn("Driver context error", "error", d.ctx.Err()) + return + } + ticker := time.NewTicker(60 * time.Second) defer func() { ticker.Stop() From 88f2164c0237747d2716e37f4654df73f18681a6 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Sat, 10 Jun 2023 14:29:15 -0400 Subject: [PATCH 05/28] add ttd uint256 to hexutil.Big --- driver/driver.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 129d5bff9..1497d5c40 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -9,10 +9,10 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" - "github.com/holiman/uint256" chainSyncer "github.com/taikoxyz/taiko-client/driver/chain_syncer" "github.com/taikoxyz/taiko-client/driver/state" "github.com/taikoxyz/taiko-client/pkg/rpc" @@ -242,15 +242,13 @@ func (d *Driver) checkTransitionConfig() { case <-d.ctx.Done(): return case <-ticker.C: - i := new(big.Int) - i.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) - ttd := new(uint256.Int) - ttd.SetFromBig(i) + tmp := new(big.Int) + tmp.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) + ttd := (*hexutil.Big)(tmp) tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ - // TerminalTotalDifficulty: 115792089237316195423570985008687907853269984665640564039457584007913129638912, - // not sure how to convert uint256 to *hexutil.Big - TerminalBlockHash: common.Hash{}, - TerminalBlockNumber: 0, + TerminalTotalDifficulty: ttd, + TerminalBlockHash: common.Hash{}, + TerminalBlockNumber: 0, }) if err != nil { log.Error("Failed to exchange Transition Configuration", "error", err) From 4a743a453cbd7cfff1ca8f2ef4f65979c9cbfa10 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Sun, 11 Jun 2023 22:57:14 -0400 Subject: [PATCH 06/28] add test --- driver/driver_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/driver/driver_test.go b/driver/driver_test.go index ad5c53852..251c35176 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -174,6 +174,12 @@ func (s *DriverTestSuite) TestStartClose() { s.d.Close() } +func (s *DriverTestSuite) TestCheckTransitionConfig() { + s.d.checkTransitionConfig() + s.cancel() + s.d.Close() +} + func TestDriverTestSuite(t *testing.T) { suite.Run(t, new(DriverTestSuite)) } From 01c5112021e8b516534597b5ae9b6a7a64468ec3 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Sun, 11 Jun 2023 23:03:37 -0400 Subject: [PATCH 07/28] add d.wg --- driver/driver.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 1497d5c40..8499dc81c 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -104,7 +104,7 @@ func InitFromConfig(ctx context.Context, d *Driver, cfg *Config) (err error) { // Start starts the driver instance. func (d *Driver) Start() error { - d.wg.Add(2) + d.wg.Add(3) go d.eventLoop() go d.reportProtocolStatus() go d.checkTransitionConfig() @@ -237,14 +237,16 @@ func (d *Driver) checkTransitionConfig() { d.wg.Done() }() + tmp := new(big.Int) + tmp.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) + ttd := (*hexutil.Big)(tmp) + for { select { case <-d.ctx.Done(): return case <-ticker.C: - tmp := new(big.Int) - tmp.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) - ttd := (*hexutil.Big)(tmp) + tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ TerminalTotalDifficulty: ttd, TerminalBlockHash: common.Hash{}, From 44de5432d1b58f001428469a24f8cc0f69801032 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Sun, 11 Jun 2023 23:12:37 -0400 Subject: [PATCH 08/28] fix --- driver/driver.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 8499dc81c..5d755d034 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -2,7 +2,6 @@ package driver import ( "context" - "math/big" "sync" "time" @@ -237,9 +236,9 @@ func (d *Driver) checkTransitionConfig() { d.wg.Done() }() - tmp := new(big.Int) - tmp.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) - ttd := (*hexutil.Big)(tmp) + // tmp := new(big.Int) + // tmp.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) + // ttd := (*hexutil.Big)(tmp) for { select { @@ -248,7 +247,7 @@ func (d *Driver) checkTransitionConfig() { case <-ticker.C: tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ - TerminalTotalDifficulty: ttd, + TerminalTotalDifficulty: (*hexutil.Big)(common.Big0), TerminalBlockHash: common.Hash{}, TerminalBlockNumber: 0, }) From e3e6c8a13036160f1ecae2289976ea1e4452d92a Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 00:53:20 -0400 Subject: [PATCH 09/28] test --- driver/driver.go | 4 ---- driver/driver_test.go | 10 ++++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 5d755d034..fc3b63507 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -236,10 +236,6 @@ func (d *Driver) checkTransitionConfig() { d.wg.Done() }() - // tmp := new(big.Int) - // tmp.SetString("115792089237316195423570985008687907853269984665640564039457584007913129638912", 10) - // ttd := (*hexutil.Big)(tmp) - for { select { case <-d.ctx.Done(): diff --git a/driver/driver_test.go b/driver/driver_test.go index 251c35176..9f6458061 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -174,8 +174,14 @@ func (s *DriverTestSuite) TestStartClose() { s.d.Close() } -func (s *DriverTestSuite) TestCheckTransitionConfig() { - s.d.checkTransitionConfig() +// func (s *DriverTestSuite) TestCheckTransitionConfig() { +// s.d.checkTransitionConfig() +// s.cancel() +// s.d.Close() +// } + +func (s *DriverTestSuite) TestReportProtocolStatus() { + s.d.reportProtocolStatus() s.cancel() s.d.Close() } From 886cf08e08e487d6c81733adeb5f7f176370ca95 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 17:26:32 -0400 Subject: [PATCH 10/28] sleep then wg.done --- driver/driver_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 9f6458061..8917a937d 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -174,18 +174,18 @@ func (s *DriverTestSuite) TestStartClose() { s.d.Close() } -// func (s *DriverTestSuite) TestCheckTransitionConfig() { -// s.d.checkTransitionConfig() -// s.cancel() -// s.d.Close() -// } - -func (s *DriverTestSuite) TestReportProtocolStatus() { - s.d.reportProtocolStatus() +func (s *DriverTestSuite) TestCheckTransitionConfig() { + s.d.checkTransitionConfig() + time.Sleep(120 * time.Second) s.cancel() - s.d.Close() + s.d.wg.Done() } +// func (s *DriverTestSuite) TestReportProtocolStatus() { +// s.d.reportProtocolStatus() +// s.d.wg.Done() +// } + func TestDriverTestSuite(t *testing.T) { suite.Run(t, new(DriverTestSuite)) } From d753c972c1c6931aba7786bb3b11ec8a9ff2b2e0 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 18:31:39 -0400 Subject: [PATCH 11/28] fix test --- driver/driver_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 8917a937d..81cb4b186 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -175,17 +175,13 @@ func (s *DriverTestSuite) TestStartClose() { } func (s *DriverTestSuite) TestCheckTransitionConfig() { + go func() { + time.After(121 * time.Second) + s.cancel() + }() s.d.checkTransitionConfig() - time.Sleep(120 * time.Second) - s.cancel() - s.d.wg.Done() } -// func (s *DriverTestSuite) TestReportProtocolStatus() { -// s.d.reportProtocolStatus() -// s.d.wg.Done() -// } - func TestDriverTestSuite(t *testing.T) { suite.Run(t, new(DriverTestSuite)) } From cd1d7f4c5aef8257d36b2080753e7e0a7cdd4d1c Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 18:32:40 -0400 Subject: [PATCH 12/28] fix chan --- driver/driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 81cb4b186..08069878e 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -176,7 +176,7 @@ func (s *DriverTestSuite) TestStartClose() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { - time.After(121 * time.Second) + <-time.After(121 * time.Second) s.cancel() }() s.d.checkTransitionConfig() From ecbe7e4e53843296b9f061f5639fba41e1018760 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 18:39:42 -0400 Subject: [PATCH 13/28] fix wg --- driver/driver_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/driver/driver_test.go b/driver/driver_test.go index 08069878e..0c9304899 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -179,6 +179,7 @@ func (s *DriverTestSuite) TestCheckTransitionConfig() { <-time.After(121 * time.Second) s.cancel() }() + s.d.wg.Add(1) s.d.checkTransitionConfig() } From 98cc4f91bb6786e5f3a778729ed999c5feb6c6ee Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 18:47:18 -0400 Subject: [PATCH 14/28] shorten test time --- driver/driver.go | 2 +- driver/driver_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index fc3b63507..7d5078ef4 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -251,7 +251,7 @@ func (d *Driver) checkTransitionConfig() { log.Error("Failed to exchange Transition Configuration", "error", err) continue } - log.Info("exchanged transition config", + log.Info("Exchanged transition config", "transitionconfig", tc) } } diff --git a/driver/driver_test.go b/driver/driver_test.go index 0c9304899..4be8207f1 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -176,7 +176,7 @@ func (s *DriverTestSuite) TestStartClose() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { - <-time.After(121 * time.Second) + <-time.After(61 * time.Second) s.cancel() }() s.d.wg.Add(1) From 53f019432c045a88098d45682904d9f9c3b7a8be Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 18:58:37 -0400 Subject: [PATCH 15/28] fix --- driver/driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 4be8207f1..e1564a14c 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -176,7 +176,7 @@ func (s *DriverTestSuite) TestStartClose() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { - <-time.After(61 * time.Second) + time.After(61 * time.Second) s.cancel() }() s.d.wg.Add(1) From 6d84b1bf2b9520db729bb9ff25c6aa5901d0305f Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 19:38:42 -0400 Subject: [PATCH 16/28] switch to Done() to prevent context error on other test --- driver/driver_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index e1564a14c..85f80eb54 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -168,21 +168,21 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { s.Nil(s.d.doSync()) } -func (s *DriverTestSuite) TestStartClose() { - s.Nil(s.d.Start()) - s.cancel() - s.d.Close() -} - func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { time.After(61 * time.Second) - s.cancel() + s.d.ctx.Done() }() s.d.wg.Add(1) s.d.checkTransitionConfig() } +func (s *DriverTestSuite) TestStartClose() { + s.Nil(s.d.Start()) + s.cancel() + s.d.Close() +} + func TestDriverTestSuite(t *testing.T) { suite.Run(t, new(DriverTestSuite)) } From 7cf9b1f23ea7bd11468baf0875efb5b499797955 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 20:25:43 -0400 Subject: [PATCH 17/28] add second driver/context to run 2 cancel tests --- driver/driver_test.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 85f80eb54..c9628a421 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -18,9 +18,11 @@ import ( type DriverTestSuite struct { testutils.ClientTestSuite - cancel context.CancelFunc - p *proposer.Proposer - d *Driver + cancel context.CancelFunc + cancel2 context.CancelFunc + p *proposer.Proposer + d *Driver + d2 *Driver } func (s *DriverTestSuite) SetupTest() { @@ -44,6 +46,18 @@ func (s *DriverTestSuite) SetupTest() { })) s.d = d + ctx2, cancel2 := context.WithCancel(context.Background()) + s.cancel2 = cancel2 + d2 := new(Driver) + InitFromConfig(ctx2, d2, &Config{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + JwtSecret: string(jwtSecret), + }) + s.d2 = d2 // Init proposer p := new(proposer.Proposer) @@ -171,10 +185,10 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { time.After(61 * time.Second) - s.d.ctx.Done() + s.cancel2() }() - s.d.wg.Add(1) - s.d.checkTransitionConfig() + s.d2.wg.Add(1) + s.d2.checkTransitionConfig() } func (s *DriverTestSuite) TestStartClose() { From 6fca5322b0714419af2a28f9291fee5d8645a8f8 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 20:42:26 -0400 Subject: [PATCH 18/28] fix lint --- driver/driver_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index c9628a421..4ab4be542 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -46,17 +46,17 @@ func (s *DriverTestSuite) SetupTest() { })) s.d = d + d2 := new(Driver) ctx2, cancel2 := context.WithCancel(context.Background()) s.cancel2 = cancel2 - d2 := new(Driver) - InitFromConfig(ctx2, d2, &Config{ + s.Nil(InitFromConfig(ctx2, d2, &Config{ L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), JwtSecret: string(jwtSecret), - }) + })) s.d2 = d2 // Init proposer p := new(proposer.Proposer) From 5c663be562d10a8d1903bd85dd6c665476d4b533 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 21:01:01 -0400 Subject: [PATCH 19/28] undo --- driver/driver_test.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 4ab4be542..edd5f19de 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -18,11 +18,9 @@ import ( type DriverTestSuite struct { testutils.ClientTestSuite - cancel context.CancelFunc - cancel2 context.CancelFunc - p *proposer.Proposer - d *Driver - d2 *Driver + cancel context.CancelFunc + p *proposer.Proposer + d *Driver } func (s *DriverTestSuite) SetupTest() { @@ -46,18 +44,6 @@ func (s *DriverTestSuite) SetupTest() { })) s.d = d - d2 := new(Driver) - ctx2, cancel2 := context.WithCancel(context.Background()) - s.cancel2 = cancel2 - s.Nil(InitFromConfig(ctx2, d2, &Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - JwtSecret: string(jwtSecret), - })) - s.d2 = d2 // Init proposer p := new(proposer.Proposer) @@ -184,11 +170,11 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { - time.After(61 * time.Second) - s.cancel2() + time.After(120 * time.Second) + s.cancel() }() - s.d2.wg.Add(1) - s.d2.checkTransitionConfig() + s.d.wg.Add(1) + s.d.checkTransitionConfig() } func (s *DriverTestSuite) TestStartClose() { From 8965bcb6619ce9d3d51c9f9b71814d4a3c6d43e7 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 21:29:53 -0400 Subject: [PATCH 20/28] add close? --- driver/driver_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/driver/driver_test.go b/driver/driver_test.go index edd5f19de..331e084fe 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -172,6 +172,7 @@ func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { time.After(120 * time.Second) s.cancel() + s.d.Close() }() s.d.wg.Add(1) s.d.checkTransitionConfig() From 4688f55224a65a2baa6c5e43e2741d8c3ddba188 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Mon, 12 Jun 2023 22:04:32 -0400 Subject: [PATCH 21/28] disable --- driver/driver_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 331e084fe..b8d0057d2 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -168,15 +168,15 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { s.Nil(s.d.doSync()) } -func (s *DriverTestSuite) TestCheckTransitionConfig() { - go func() { - time.After(120 * time.Second) - s.cancel() - s.d.Close() - }() - s.d.wg.Add(1) - s.d.checkTransitionConfig() -} +// func (s *DriverTestSuite) TestCheckTransitionConfig() { +// go func() { +// time.After(120 * time.Second) +// s.cancel() +// s.d.Close() +// }() +// s.d.wg.Add(1) +// s.d.checkTransitionConfig() +// } func (s *DriverTestSuite) TestStartClose() { s.Nil(s.d.Start()) From acb5b88e1b1741874e42a228047328982d8b3d59 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 13 Jun 2023 00:26:07 -0400 Subject: [PATCH 22/28] logs --- driver/driver.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/driver/driver.go b/driver/driver.go index 7d5078ef4..34576a858 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -115,6 +115,7 @@ func (d *Driver) Start() error { func (d *Driver) Close() { d.state.Close() d.wg.Wait() + log.Info("close.Done()") } // eventLoop starts the main loop of a L2 execution engine's driver. @@ -184,6 +185,7 @@ func (d *Driver) reportProtocolStatus() { defer func() { ticker.Stop() d.wg.Done() + log.Info("protocolStatus.Done()") }() var maxNumBlocks uint64 @@ -234,6 +236,7 @@ func (d *Driver) checkTransitionConfig() { defer func() { ticker.Stop() d.wg.Done() + log.Info("transition.Done()") }() for { From 1fa54836c5eda77a34cf36541e1d740b1637be84 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 13 Jun 2023 20:41:23 -0400 Subject: [PATCH 23/28] more logs --- driver/driver.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/driver/driver.go b/driver/driver.go index 2ce372cd5..2dd4e8916 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -209,6 +209,7 @@ func (d *Driver) reportProtocolStatus() { for { select { case <-d.ctx.Done(): + log.Info("protocol context exited") return case <-ticker.C: vars, err := d.rpc.GetProtocolStateVariables(nil) @@ -243,6 +244,7 @@ func (d *Driver) checkTransitionConfig() { for { select { case <-d.ctx.Done(): + log.Info("transition context exited") return case <-ticker.C: From 223df421c10247bad50ea086e0c035ec9002afe1 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 13 Jun 2023 20:56:35 -0400 Subject: [PATCH 24/28] more logs, disable check --- driver/driver.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 2dd4e8916..df919427b 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -146,6 +146,7 @@ func (d *Driver) eventLoop() { for { select { case <-d.ctx.Done(): + log.Info("eventLoop context exited") return case <-d.syncNotify: doSyncWithBackoff() @@ -229,12 +230,12 @@ func (d *Driver) reportProtocolStatus() { } func (d *Driver) checkTransitionConfig() { - if d.ctx.Err() != nil { - log.Warn("Driver context error", "error", d.ctx.Err()) - return - } - - ticker := time.NewTicker(60 * time.Second) + exchangeTransitionConfigInterval := 60 * time.Second + ticker := time.NewTicker(exchangeTransitionConfigInterval) + // if d.ctx.Err() != nil { + // log.Warn("Driver context error", "error", d.ctx.Err()) + // return + // } defer func() { ticker.Stop() d.wg.Done() @@ -247,7 +248,7 @@ func (d *Driver) checkTransitionConfig() { log.Info("transition context exited") return case <-ticker.C: - + log.Info("exchanging transition config") tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ TerminalTotalDifficulty: (*hexutil.Big)(common.Big0), TerminalBlockHash: common.Hash{}, From aa17d611807872c343d0bbd23273c397e0a2ff53 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 13 Jun 2023 21:02:53 -0400 Subject: [PATCH 25/28] remove logs, reenable test --- driver/driver.go | 12 +----------- driver/driver_test.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index df919427b..bef2616a7 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -117,7 +117,6 @@ func (d *Driver) Start() error { func (d *Driver) Close() { d.state.Close() d.wg.Wait() - log.Info("close.Done()") } // eventLoop starts the main loop of a L2 execution engine's driver. @@ -146,7 +145,6 @@ func (d *Driver) eventLoop() { for { select { case <-d.ctx.Done(): - log.Info("eventLoop context exited") return case <-d.syncNotify: doSyncWithBackoff() @@ -187,7 +185,6 @@ func (d *Driver) reportProtocolStatus() { defer func() { ticker.Stop() d.wg.Done() - log.Info("protocolStatus.Done()") }() var maxNumBlocks uint64 @@ -210,7 +207,6 @@ func (d *Driver) reportProtocolStatus() { for { select { case <-d.ctx.Done(): - log.Info("protocol context exited") return case <-ticker.C: vars, err := d.rpc.GetProtocolStateVariables(nil) @@ -232,23 +228,17 @@ func (d *Driver) reportProtocolStatus() { func (d *Driver) checkTransitionConfig() { exchangeTransitionConfigInterval := 60 * time.Second ticker := time.NewTicker(exchangeTransitionConfigInterval) - // if d.ctx.Err() != nil { - // log.Warn("Driver context error", "error", d.ctx.Err()) - // return - // } + defer func() { ticker.Stop() d.wg.Done() - log.Info("transition.Done()") }() for { select { case <-d.ctx.Done(): - log.Info("transition context exited") return case <-ticker.C: - log.Info("exchanging transition config") tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ TerminalTotalDifficulty: (*hexutil.Big)(common.Big0), TerminalBlockHash: common.Hash{}, diff --git a/driver/driver_test.go b/driver/driver_test.go index b8d0057d2..007ff52d9 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -168,15 +168,15 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { s.Nil(s.d.doSync()) } -// func (s *DriverTestSuite) TestCheckTransitionConfig() { -// go func() { -// time.After(120 * time.Second) -// s.cancel() -// s.d.Close() -// }() -// s.d.wg.Add(1) -// s.d.checkTransitionConfig() -// } +func (s *DriverTestSuite) TestCheckTransitionConfig() { + go func() { + time.After(70 * time.Second) + s.cancel() + s.d.Close() + }() + s.d.wg.Add(1) + s.d.checkTransitionConfig() +} func (s *DriverTestSuite) TestStartClose() { s.Nil(s.d.Start()) From 40b4fe03a98e0b6db3ebb96953fc0769fe1b20c0 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 13 Jun 2023 21:21:11 -0400 Subject: [PATCH 26/28] extend time.after --- driver/driver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 007ff52d9..331e084fe 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -170,7 +170,7 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { - time.After(70 * time.Second) + time.After(120 * time.Second) s.cancel() s.d.Close() }() From 7f9fc17fc5efecafaed7387375c25b2dc31574c8 Mon Sep 17 00:00:00 2001 From: RogerLamTd Date: Tue, 13 Jun 2023 21:54:44 -0400 Subject: [PATCH 27/28] fix test? --- driver/driver.go | 1 - driver/driver_test.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index bef2616a7..1697c1235 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -228,7 +228,6 @@ func (d *Driver) reportProtocolStatus() { func (d *Driver) checkTransitionConfig() { exchangeTransitionConfigInterval := 60 * time.Second ticker := time.NewTicker(exchangeTransitionConfigInterval) - defer func() { ticker.Stop() d.wg.Done() diff --git a/driver/driver_test.go b/driver/driver_test.go index 331e084fe..b88c2fe51 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -170,7 +170,7 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { func (s *DriverTestSuite) TestCheckTransitionConfig() { go func() { - time.After(120 * time.Second) + <-time.After(120 * time.Second) s.cancel() s.d.Close() }() From ed5e749c841c27d18b9fcbddc5b97eb38fb457fb Mon Sep 17 00:00:00 2001 From: David Date: Thu, 15 Jun 2023 14:11:39 +0800 Subject: [PATCH 28/28] feat: improve some code --- driver/driver.go | 41 ++++++++++++++++++++++++++--------------- driver/driver_test.go | 10 ---------- pkg/rpc/engine.go | 6 ++---- pkg/rpc/engine_test.go | 9 +++++++++ 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index 1697c1235..6c13ef870 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -19,7 +19,9 @@ import ( ) const ( - protocolStatusReportInterval = 30 * time.Second + protocolStatusReportInterval = 30 * time.Second + exchangeTransitionConfigTimeout = 30 * time.Second + exchangeTransitionConfigInterval = 1 * time.Minute ) // Driver keeps the L2 execution engine's local block chain in sync with the TaikoL1 @@ -108,7 +110,7 @@ func (d *Driver) Start() error { d.wg.Add(3) go d.eventLoop() go d.reportProtocolStatus() - go d.checkTransitionConfig() + go d.exchangeTransitionConfigLoop() return nil } @@ -225,8 +227,9 @@ func (d *Driver) reportProtocolStatus() { } } -func (d *Driver) checkTransitionConfig() { - exchangeTransitionConfigInterval := 60 * time.Second +// exchangeTransitionConfigLoop keeps exchanging transition configs with the +// L2 execution engine. +func (d *Driver) exchangeTransitionConfigLoop() { ticker := time.NewTicker(exchangeTransitionConfigInterval) defer func() { ticker.Stop() @@ -238,17 +241,25 @@ func (d *Driver) checkTransitionConfig() { case <-d.ctx.Done(): return case <-ticker.C: - tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(d.ctx, &engine.TransitionConfigurationV1{ - TerminalTotalDifficulty: (*hexutil.Big)(common.Big0), - TerminalBlockHash: common.Hash{}, - TerminalBlockNumber: 0, - }) - if err != nil { - log.Error("Failed to exchange Transition Configuration", "error", err) - continue - } - log.Info("Exchanged transition config", - "transitionconfig", tc) + func() { + ctx, cancel := context.WithTimeout(d.ctx, exchangeTransitionConfigTimeout) + defer cancel() + + tc, err := d.rpc.L2Engine.ExchangeTransitionConfiguration(ctx, &engine.TransitionConfigurationV1{ + TerminalTotalDifficulty: (*hexutil.Big)(common.Big0), + TerminalBlockHash: common.Hash{}, + TerminalBlockNumber: 0, + }) + if err != nil { + log.Error("Failed to exchange Transition Configuration", "error", err) + return + } + + log.Debug( + "Exchanged transition config", + "transitionConfig", tc, + ) + }() } } } diff --git a/driver/driver_test.go b/driver/driver_test.go index b88c2fe51..ad5c53852 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -168,16 +168,6 @@ func (s *DriverTestSuite) TestDoSyncNoNewL2Blocks() { s.Nil(s.d.doSync()) } -func (s *DriverTestSuite) TestCheckTransitionConfig() { - go func() { - <-time.After(120 * time.Second) - s.cancel() - s.d.Close() - }() - s.d.wg.Add(1) - s.d.checkTransitionConfig() -} - func (s *DriverTestSuite) TestStartClose() { s.Nil(s.d.Start()) s.cancel() diff --git a/pkg/rpc/engine.go b/pkg/rpc/engine.go index 8a9adceaa..1516e3b25 100644 --- a/pkg/rpc/engine.go +++ b/pkg/rpc/engine.go @@ -64,15 +64,13 @@ func (c *EngineClient) GetPayload( return result.ExecutionPayload, nil } +// ExchangeTransitionConfiguration exchanges transition configs with the L2 execution engine. func (c *EngineClient) ExchangeTransitionConfiguration( ctx context.Context, cfg *engine.TransitionConfigurationV1, ) (*engine.TransitionConfigurationV1, error) { - timeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second) - defer cancel() - var result *engine.TransitionConfigurationV1 - if err := c.Client.CallContext(timeoutCtx, &result, "engine_exchangeTransitionConfigurationV1", cfg); err != nil { + if err := c.Client.CallContext(ctx, &result, "engine_exchangeTransitionConfigurationV1", cfg); err != nil { return nil, err } diff --git a/pkg/rpc/engine_test.go b/pkg/rpc/engine_test.go index e10d4c88e..de63db04e 100644 --- a/pkg/rpc/engine_test.go +++ b/pkg/rpc/engine_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/ethereum/go-ethereum/beacon/engine" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/stretchr/testify/require" ) @@ -29,4 +31,11 @@ func TestL2EngineBorbidden(t *testing.T) { &engine.PayloadID{}, ) require.ErrorContains(t, err, "Unauthorized") + + _, err = c.L2Engine.ExchangeTransitionConfiguration(context.Background(), &engine.TransitionConfigurationV1{ + TerminalTotalDifficulty: (*hexutil.Big)(common.Big0), + TerminalBlockHash: common.Hash{}, + TerminalBlockNumber: 0, + }) + require.ErrorContains(t, err, "Unauthorized") }