Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(all): disable no beacon client seen warning (#279)
Browse files Browse the repository at this point in the history
Co-authored-by: David <david@taiko.xyz>
  • Loading branch information
RogerLamTd and davidtaikocha committed Jun 15, 2023
1 parent 2df4105 commit cdabcac
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
47 changes: 45 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"time"

"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"
Expand All @@ -16,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
Expand Down Expand Up @@ -102,9 +107,10 @@ 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.exchangeTransitionConfigLoop()

return nil
}
Expand Down Expand Up @@ -221,6 +227,43 @@ func (d *Driver) reportProtocolStatus() {
}
}

// exchangeTransitionConfigLoop keeps exchanging transition configs with the
// L2 execution engine.
func (d *Driver) exchangeTransitionConfigLoop() {
ticker := time.NewTicker(exchangeTransitionConfigInterval)
defer func() {
ticker.Stop()
d.wg.Done()
}()

for {
select {
case <-d.ctx.Done():
return
case <-ticker.C:
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,
)
}()
}
}
}

// Name returns the application name.
func (d *Driver) Name() string {
return "driver"
Expand Down
13 changes: 13 additions & 0 deletions pkg/rpc/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ 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) {
var result *engine.TransitionConfigurationV1
if err := c.Client.CallContext(ctx, &result, "engine_exchangeTransitionConfigurationV1", cfg); err != nil {
return nil, err
}

return result, nil
}
9 changes: 9 additions & 0 deletions pkg/rpc/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
}

0 comments on commit cdabcac

Please sign in to comment.