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

Commit

Permalink
feat(all): some client optimizations (#376)
Browse files Browse the repository at this point in the history
Co-authored-by: alexshliu <[email protected]>
Co-authored-by: John Chase <[email protected]>
  • Loading branch information
3 people committed Sep 7, 2023
1 parent 04654ff commit 91bba90
Show file tree
Hide file tree
Showing 46 changed files with 1,014 additions and 924 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
cache: true

- name: Lint
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
cache: true
cache-dependency-path: ${{ env.CLIENT_DIR }}/go.sum

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine as builder
FROM golang:1.21-alpine as builder

RUN apk add --no-cache gcc musl-dev linux-headers git make

Expand Down
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c8969b64bbaacf9ec6d239608509424fdc02ee97
8028a49ea2dfc123b1c818afb722a029d3743e5c
4 changes: 2 additions & 2 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
Type: "bytes32",
},
{
Name: "beneficiary",
Name: "proposer",
Type: "address",
},
{
Expand Down Expand Up @@ -76,7 +76,7 @@ var (
Type: "uint32",
},
{
Name: "beneficiary",
Name: "proposer",
Type: "address",
},
{
Expand Down
4 changes: 2 additions & 2 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestEncodeBlockMetadata(t *testing.T) {
Id: uint64(1),
L1Height: uint64(1),
L1Hash: abcdBytes,
Beneficiary: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
Proposer: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
TxListHash: abcdBytes,
TxListByteStart: big.NewInt(0),
TxListByteEnd: big.NewInt(1000),
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestEncodeBlockMetadata(t *testing.T) {
Id: uint64(1),
L1Height: uint64(1),
L1Hash: abcdBytes,
Beneficiary: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
Proposer: common.HexToAddress("0x10020FCb72e27650651B05eD2CEcA493bC807Ba4"),
TxListHash: abcdBytes,
TxListByteStart: big.NewInt(0),
TxListByteEnd: big.NewInt(1000),
Expand Down
2 changes: 1 addition & 1 deletion bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type TaikoL1Evidence struct {

type TaikoL1BlockMetadataInput struct {
TxListHash [32]byte
Beneficiary common.Address
Proposer common.Address
TxListByteStart *big.Int
TxListByteEnd *big.Int
CacheTxListInfo bool
Expand Down
9 changes: 5 additions & 4 deletions bindings/encoding/struct_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package encoding

import (
cryptoRand "crypto/rand"
"math/big"
"math/rand"
"testing"
Expand Down Expand Up @@ -33,7 +34,7 @@ var (
BaseFee: new(big.Int).SetUint64(rand.Uint64()),
}
testMetaInput = TaikoL1BlockMetadataInput{
Beneficiary: common.BytesToAddress(randomHash().Bytes()),
Proposer: common.BytesToAddress(randomHash().Bytes()),
TxListHash: randomHash(),
TxListByteStart: common.Big0,
TxListByteEnd: common.Big0,
Expand All @@ -49,7 +50,7 @@ var (
TxListByteStart: common.Big0,
TxListByteEnd: common.Big256,
GasLimit: rand.Uint32(),
Beneficiary: common.BytesToAddress(randomHash().Bytes()),
Proposer: common.BytesToAddress(randomHash().Bytes()),
DepositsProcessed: []bindings.TaikoDataEthDeposit{},
}
)
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestToExecutableData(t *testing.T) {
// randomHash generates a random blob of data and returns it as a hash.
func randomHash() common.Hash {
var hash common.Hash
if n, err := rand.Read(hash[:]); n != common.HashLength || err != nil {
if n, err := cryptoRand.Read(hash[:]); n != common.HashLength || err != nil {
panic(err)
}
return hash
Expand All @@ -131,7 +132,7 @@ func randomHash() common.Hash {
// randomBytes generates a random bytes.
func randomBytes(size int) (b []byte) {
b = make([]byte, size)
if _, err := rand.Read(b); err != nil {
if _, err := cryptoRand.Read(b); err != nil {
log.Crit("Generate random bytes error", "error", err)
}
return
Expand Down
11 changes: 5 additions & 6 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package main

import (
"fmt"
"math/rand"
"os"
"time"

"github.com/taikoxyz/taiko-client/cmd/flags"
"github.com/taikoxyz/taiko-client/cmd/utils"
Expand All @@ -15,10 +13,6 @@ import (
"github.com/urfave/cli/v2"
)

func init() {
rand.Seed(time.Now().UnixNano())
}

func main() {
app := cli.NewApp()

Expand Down
4 changes: 2 additions & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ func (s *Syncer) createExecutionPayloads(
attributes := &engine.PayloadAttributes{
Timestamp: event.Meta.Timestamp,
Random: event.Meta.MixHash,
SuggestedFeeRecipient: event.Meta.Beneficiary,
SuggestedFeeRecipient: event.Meta.Proposer,
Withdrawals: withdrawals,
BlockMetadata: &engine.BlockMetadata{
HighestBlockID: headBlockID,
Beneficiary: event.Meta.Beneficiary,
Beneficiary: event.Meta.Proposer,
GasLimit: uint64(event.Meta.GasLimit) + s.anchorConstructor.GasLimit(),
Timestamp: event.Meta.Timestamp,
TxList: txListBytes,
Expand Down
67 changes: 25 additions & 42 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package calldata

import (
"context"
"fmt"
"math/big"
"math/rand"
"os"
Expand All @@ -17,23 +16,18 @@ import (
"github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-client/driver/state"
"github.com/taikoxyz/taiko-client/proposer"
"github.com/taikoxyz/taiko-client/prover/http"
"github.com/taikoxyz/taiko-client/testutils"
)

type CalldataSyncerTestSuite struct {
testutils.ClientTestSuite
s *Syncer
p testutils.Proposer
srv *http.Server
cancel context.CancelFunc
s *Syncer
p testutils.Proposer
}

func (s *CalldataSyncerTestSuite) SetupTest() {
s.ClientTestSuite.SetupTest()

port := testutils.RandomPort()

state, err := state.New(context.Background(), s.RpcClient)
s.Nil(err)

Expand All @@ -51,32 +45,27 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
l1ProposerPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_PROPOSER_PRIVATE_KEY")))
s.Nil(err)
proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests

s.Nil(proposer.InitFromConfig(context.Background(), prop, (&proposer.Config{
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 10 * time.Second,
ProverEndpoints: []string{fmt.Sprintf("http://localhost:%v", port)},
BlockProposalFee: big.NewInt(1000),
BlockProposalFeeIterations: 3,
L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"),
L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"),
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")),
TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")),
L1ProposerPrivKey: l1ProposerPrivKey,
L2SuggestedFeeRecipient: common.HexToAddress(os.Getenv("L2_SUGGESTED_FEE_RECIPIENT")),
ProposeInterval: &proposeInterval,
MaxProposedTxListsPerEpoch: 1,
WaitReceiptTimeout: 10 * time.Second,
ProverEndpoints: s.ProverEndpoints,
BlockProposalFee: big.NewInt(1000),
BlockProposalFeeIterations: 3,
BlockProposalFeeIncreasePercentage: common.Big2,
})))

srv, cancel, err := testutils.HTTPServer(&s.ClientTestSuite, port)
s.Nil(err)

s.srv = srv
s.cancel = cancel

s.p = prop
}
func (s *CalldataSyncerTestSuite) TestCancelNewSyncer() {
defer s.cancel()
ctx, cancel := context.WithCancel(context.Background())
cancel()
syncer, err := NewSyncer(
Expand All @@ -91,22 +80,19 @@ func (s *CalldataSyncerTestSuite) TestCancelNewSyncer() {
}

func (s *CalldataSyncerTestSuite) TestProcessL1Blocks() {
defer s.cancel()
head, err := s.s.rpc.L1.HeaderByNumber(context.Background(), nil)
s.Nil(err)
s.Nil(s.s.ProcessL1Blocks(context.Background(), head))
}

func (s *CalldataSyncerTestSuite) TestProcessL1BlocksReorg() {
defer s.cancel()
head, err := s.s.rpc.L1.HeaderByNumber(context.Background(), nil)
testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s)
s.Nil(err)
s.Nil(s.s.ProcessL1Blocks(context.Background(), head))
}

func (s *CalldataSyncerTestSuite) TestOnBlockProposed() {
defer s.cancel()
s.Nil(s.s.onBlockProposed(
context.Background(),
&bindings.TaikoL1ClientBlockProposed{BlockId: common.Big0},
Expand All @@ -120,7 +106,6 @@ func (s *CalldataSyncerTestSuite) TestOnBlockProposed() {
}

func (s *CalldataSyncerTestSuite) TestInsertNewHead() {
defer s.cancel()
parent, err := s.s.rpc.L2.HeaderByNumber(context.Background(), nil)
s.Nil(err)
l1Head, err := s.s.rpc.L1.BlockByNumber(context.Background(), nil)
Expand All @@ -130,14 +115,14 @@ func (s *CalldataSyncerTestSuite) TestInsertNewHead() {
&bindings.TaikoL1ClientBlockProposed{
BlockId: common.Big1,
Meta: bindings.TaikoDataBlockMetadata{
Id: 1,
L1Height: l1Head.NumberU64(),
L1Hash: l1Head.Hash(),
Beneficiary: common.BytesToAddress(testutils.RandomBytes(1024)),
TxListHash: testutils.RandomHash(),
MixHash: testutils.RandomHash(),
GasLimit: rand.Uint32(),
Timestamp: uint64(time.Now().Unix()),
Id: 1,
L1Height: l1Head.NumberU64(),
L1Hash: l1Head.Hash(),
Proposer: common.BytesToAddress(testutils.RandomBytes(1024)),
TxListHash: testutils.RandomHash(),
MixHash: testutils.RandomHash(),
GasLimit: rand.Uint32(),
Timestamp: uint64(time.Now().Unix()),
},
},
parent,
Expand All @@ -153,7 +138,6 @@ func (s *CalldataSyncerTestSuite) TestInsertNewHead() {
}

func (s *CalldataSyncerTestSuite) TestTreasuryIncomeAllAnchors() {
defer s.cancel()
treasury := common.HexToAddress(os.Getenv("TREASURY"))
s.NotZero(treasury.Big().Uint64())

Expand All @@ -176,7 +160,6 @@ func (s *CalldataSyncerTestSuite) TestTreasuryIncomeAllAnchors() {
}

func (s *CalldataSyncerTestSuite) TestTreasuryIncome() {
defer s.cancel()
treasury := common.HexToAddress(os.Getenv("TREASURY"))
s.NotZero(treasury.Big().Uint64())

Expand Down
Loading

0 comments on commit 91bba90

Please sign in to comment.