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

Commit

Permalink
Merge branch 'main' into guardian_prover_key_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Jan 23, 2024
2 parents 37f7920 + bbe9ed7 commit 5a01f94
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 206 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ linters:
- gofmt
- ineffassign
- importas
- lll
- makezero
- misspell
- misspell
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/sub_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func SubcommandAction(app SubcommandApplication) cli.ActionFunc {
logger.InitLogger(c)

ctx, ctxClose := context.WithCancel(context.Background())
defer func() { ctxClose() }()
defer ctxClose()

if err := app.InitFromCli(ctx, c); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion driver/anchor_tx_constructor/anchor_tx_constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *AnchorTxConstructor) AssembleAnchorTx(
return nil, err
}

signalRoot, err := c.rpc.GetStorageRoot(ctx, c.rpc.L1GethClient, c.signalServiceAddress, l1Height)
signalRoot, err := c.rpc.GetStorageRoot(ctx, c.rpc.L1, c.signalServiceAddress, l1Height)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ func TestChainSyncerTestSuite(t *testing.T) {

func (s *ChainSyncerTestSuite) TakeSnapshot() {
// record snapshot state to revert to before changes
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &s.snapshotID, "evm_snapshot"))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &s.snapshotID, "evm_snapshot"))
}

func (s *ChainSyncerTestSuite) RevertSnapshot() {
// revert to the snapshot state so protocol configs are unaffected
var revertRes bool
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", s.snapshotID))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", s.snapshotID))
s.True(revertRes)
s.Nil(rpc.SetHead(context.Background(), s.RPCClient.L2RawRPC, common.Big0))
s.Nil(rpc.SetHead(context.Background(), s.RPCClient.L2, common.Big0))
}

func (s *ChainSyncerTestSuite) TestAheadOfProtocolVerifiedHead() {
Expand Down
12 changes: 6 additions & 6 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (s *DriverTestSuite) TestProcessL1Blocks() {

func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() {
var testnetL1SnapshotID string
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
s.NotEmpty(testnetL1SnapshotID)

l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() {

// Reorg back to l2Head1
var revertRes bool
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
s.True(revertRes)

l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
Expand Down Expand Up @@ -191,7 +191,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() {

func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() {
var testnetL1SnapshotID string
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
s.NotEmpty(testnetL1SnapshotID)

l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
Expand Down Expand Up @@ -221,7 +221,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() {

// Reorg back to l2Head1
var revertRes bool
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
s.True(revertRes)

l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
Expand Down Expand Up @@ -251,7 +251,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() {

func (s *DriverTestSuite) TestCheckL1ReorgToSameHeightFork() {
var testnetL1SnapshotID string
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
s.NotEmpty(testnetL1SnapshotID)

l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
Expand Down Expand Up @@ -281,7 +281,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToSameHeightFork() {

// Reorg back to l2Head1
var revertRes bool
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
s.True(revertRes)

l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
Expand All @@ -56,6 +57,7 @@ require (
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
Expand All @@ -73,6 +75,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
Expand All @@ -86,6 +89,7 @@ require (
github.com/prysmaticlabs/gohashtree v0.0.3-alpha // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand All @@ -107,6 +111,7 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
Expand Down
10 changes: 5 additions & 5 deletions internal/testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *ClientTestSuite) SetupTest() {
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)
}
s.Nil(rpcCli.L1RawRPC.CallContext(context.Background(), &s.testnetL1SnapshotID, "evm_snapshot"))
s.Nil(rpcCli.L1.CallContext(context.Background(), &s.testnetL1SnapshotID, "evm_snapshot"))
s.NotEmpty(s.testnetL1SnapshotID)
}

Expand Down Expand Up @@ -175,19 +175,19 @@ func (s *ClientTestSuite) setAddress(ownerPrivKey *ecdsa.PrivateKey, name [32]by

func (s *ClientTestSuite) TearDownTest() {
var revertRes bool
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", s.testnetL1SnapshotID))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", s.testnetL1SnapshotID))
s.True(revertRes)

s.Nil(rpc.SetHead(context.Background(), s.RPCClient.L2RawRPC, common.Big0))
s.Nil(rpc.SetHead(context.Background(), s.RPCClient.L2, common.Big0))
s.Nil(s.proverServer.Shutdown(context.Background()))
}

func (s *ClientTestSuite) SetL1Automine(automine bool) {
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), nil, "evm_setAutomine", automine))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), nil, "evm_setAutomine", automine))
}

func (s *ClientTestSuite) IncreaseTime(time uint64) {
var result uint64
s.Nil(s.RPCClient.L1RawRPC.CallContext(context.Background(), &result, "evm_increaseTime", time))
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &result, "evm_increaseTime", time))
s.NotNil(result)
}
90 changes: 22 additions & 68 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
"github.com/ethereum/go-ethereum/rpc"

"github.com/taikoxyz/taiko-client/bindings"
)

Expand All @@ -24,12 +21,6 @@ type Client struct {
L1 *EthClient
L2 *EthClient
L2CheckPoint *EthClient
// Geth gethclient clients
L1GethClient *gethclient.Client
L2GethClient *gethclient.Client
// Geth raw RPC clients
L1RawRPC *rpc.Client
L2RawRPC *rpc.Client
// Geth Engine API clients
L2Engine *EngineClient
// Protocol contracts clients
Expand Down Expand Up @@ -65,33 +56,32 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout)
defer cancel()

if cfg.BackOffMaxRetries == 0 {
cfg.BackOffMaxRetries = 10
l1Client, err := NewEthClient(ctxWithTimeout, cfg.L1Endpoint, cfg.Timeout)
if err != nil {
return nil, err
}

l1EthClient, err := DialClientWithBackoff(ctxWithTimeout, cfg.L1Endpoint, cfg.RetryInterval, cfg.BackOffMaxRetries)
l2Client, err := NewEthClient(ctxWithTimeout, cfg.L2Endpoint, cfg.Timeout)
if err != nil {
return nil, err
}

l2EthClient, err := DialClientWithBackoff(ctxWithTimeout, cfg.L2Endpoint, cfg.RetryInterval, cfg.BackOffMaxRetries)
l1ChainID, err := l1Client.ChainID(ctxWithTimeout)
if err != nil {
return nil, err
}

var (
l1RPC *EthClient
l2RPC *EthClient
)
l1RPC = NewEthClientWithTimeout(l1EthClient, cfg.Timeout)
l2RPC = NewEthClientWithTimeout(l2EthClient, cfg.Timeout)
l2ChainID, err := l2Client.ChainID(ctxWithTimeout)
if err != nil {
return nil, err
}

taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1RPC)
taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1Client)
if err != nil {
return nil, err
}

taikoL2, err := bindings.NewTaikoL2Client(cfg.TaikoL2Address, l2RPC)
taikoL2, err := bindings.NewTaikoL2Client(cfg.TaikoL2Address, l2Client)
if err != nil {
return nil, err
}
Expand All @@ -101,12 +91,12 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
guardianProver *bindings.GuardianProver
)
if cfg.TaikoTokenAddress.Hex() != ZeroAddress.Hex() {
if taikoToken, err = bindings.NewTaikoToken(cfg.TaikoTokenAddress, l1RPC); err != nil {
if taikoToken, err = bindings.NewTaikoToken(cfg.TaikoTokenAddress, l1Client); err != nil {
return nil, err
}
}
if cfg.GuardianProverAddress.Hex() != ZeroAddress.Hex() {
if guardianProver, err = bindings.NewGuardianProver(cfg.GuardianProverAddress, l1RPC); err != nil {
if guardianProver, err = bindings.NewGuardianProver(cfg.GuardianProverAddress, l1Client); err != nil {
return nil, err
}
}
Expand All @@ -115,73 +105,37 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
if err != nil {
return nil, err
}

isArchive, err := IsArchiveNode(ctxWithTimeout, l1RPC, stateVars.A.GenesisHeight)
isArchive, err := IsArchiveNode(ctxWithTimeout, l1Client, stateVars.A.GenesisHeight)
if err != nil {
return nil, err
}

if !isArchive {
return nil, fmt.Errorf("error with RPC endpoint: node (%s) must be archive node", cfg.L1Endpoint)
}

l1RawRPC, err := rpc.Dial(cfg.L1Endpoint)
if err != nil {
return nil, err
}

l2RawRPC, err := rpc.Dial(cfg.L2Endpoint)
if err != nil {
return nil, err
}

l1ChainID, err := l1RPC.ChainID(ctxWithTimeout)
if err != nil {
return nil, err
}

l2ChainID, err := l2RPC.ChainID(ctxWithTimeout)
if err != nil {
return nil, err
}

// If not providing L2EngineEndpoint or JwtSecret, then the L2Engine client
// won't be initialized.
var l2AuthRPC *EngineClient
var l2AuthClient *EngineClient
if len(cfg.L2EngineEndpoint) != 0 && len(cfg.JwtSecret) != 0 {
if l2AuthRPC, err = DialEngineClientWithBackoff(
ctxWithTimeout,
cfg.L2EngineEndpoint,
cfg.JwtSecret,
cfg.RetryInterval,
cfg.BackOffMaxRetries,
); err != nil {
l2AuthClient, err = NewJWTEngineClient(cfg.L2EngineEndpoint, cfg.JwtSecret)
if err != nil {
return nil, err
}
}

var l2CheckPoint *EthClient
if len(cfg.L2CheckPoint) != 0 {
l2CheckPointEthClient, err := DialClientWithBackoff(
ctxWithTimeout,
cfg.L2CheckPoint,
cfg.RetryInterval,
cfg.BackOffMaxRetries)
if cfg.L2CheckPoint != "" {
l2CheckPoint, err = NewEthClient(ctxWithTimeout, cfg.L2CheckPoint, cfg.Timeout)
if err != nil {
return nil, err
}
l2CheckPoint = NewEthClientWithTimeout(l2CheckPointEthClient, cfg.Timeout)
}

client := &Client{
L1: l1RPC,
L2: l2RPC,
L1: l1Client,
L2: l2Client,
L2CheckPoint: l2CheckPoint,
L1RawRPC: l1RawRPC,
L2RawRPC: l2RawRPC,
L1GethClient: gethclient.New(l1RawRPC),
L2GethClient: gethclient.New(l2RawRPC),
L2Engine: l2AuthRPC,
L2Engine: l2AuthClient,
TaikoL1: taikoL1,
TaikoL2: taikoL2,
TaikoToken: taikoToken,
Expand Down
Loading

0 comments on commit 5a01f94

Please sign in to comment.