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

Commit

Permalink
Merge branch 'eip4844' into eip4844_docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp committed Feb 2, 2024
2 parents 538a9c7 + f725fc1 commit a90a152
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 28 deletions.
3 changes: 2 additions & 1 deletion cmd/flags/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
Required: true,
Category: driverCategory,
}
L1CCEndpoint = &cli.StringFlag{
L1BeaconEndpoint = &cli.StringFlag{
Name: "l1.beacon",
Usage: "HTTP RPC endpoint of a L1 consensus client",
Required: true,
Expand Down Expand Up @@ -53,6 +53,7 @@ var (

// DriverFlags All driver flags.
var DriverFlags = MergeFlags(CommonFlags, []cli.Flag{
L1BeaconEndpoint,
L2WSEndpoint,
L2AuthEndpoint,
JWTSecret,
Expand Down
12 changes: 9 additions & 3 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ var (
Category: proposerCategory,
}
BlobAllowed = &cli.BoolFlag{
Name: "blobAllowed",
Usage: "Send blob tx when propose block",
Value: false,
Name: "blobAllowed",
Usage: "Send blob tx when propose block",
Value: false,
}
L1BlockBuilderTip = &cli.Uint64Flag{
Name: "l1BlockBuilderTip",
Usage: "Amount you wish to tip the L1 block builder",
Value: 0,
Category: proposerCategory,
}
)
Expand Down Expand Up @@ -154,4 +159,5 @@ var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
ProposeBlockIncludeParentMetaHash,
ProposerAssignmentHookAddress,
BlobAllowed,
L1BlockBuilderTip,
})
16 changes: 14 additions & 2 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
anchorTxConstructor "github.com/taikoxyz/taiko-client/driver/anchor_tx_constructor"
"github.com/taikoxyz/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-client/driver/state"
txlistfetcher "github.com/taikoxyz/taiko-client/driver/txlist_fetcher"
"github.com/taikoxyz/taiko-client/internal/metrics"
eventIterator "github.com/taikoxyz/taiko-client/pkg/chain_iterator/event_iterator"
"github.com/taikoxyz/taiko-client/pkg/rpc"
Expand Down Expand Up @@ -235,11 +236,22 @@ func (s *Syncer) onBlockProposed(
event.Raw.TxIndex,
)
if err != nil {
return fmt.Errorf("failed to fetch original TaikoL1.proposeBlock transaction: %w", err)
return fmt.Errorf("failed to fetch original TaikoL1.ProposeBlock transaction: %w", err)
}

var txListDecoder txlistfetcher.TxListFetcher
if event.Meta.BlobUsed {
txListDecoder = txlistfetcher.NewBlobTxListFetcher(s.rpc)
} else {
txListDecoder = &txlistfetcher.CalldataFetcher{}
}
txListBytes, err := txListDecoder.Fetch(ctx, tx, &event.Meta)
if err != nil {
return fmt.Errorf("failed to decode tx list: %w", err)
}

// Check whether the transactions list is valid.
txListBytes, hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.BlockId, tx.Data())
hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.BlockId, txListBytes)
if err != nil {
return fmt.Errorf("failed to validate transactions list: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (s *CalldataSyncerTestSuite) SetupTest() {
SgxAndPseZkevmTierFee: common.Big256,
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
L1BlockBuilderTip: common.Big0,
}))

s.p = prop
Expand Down
1 change: 1 addition & 0 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (s *ChainSyncerTestSuite) SetupTest() {
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
ExtraData: "test",
L1BlockBuilderTip: common.Big0,
}))

s.p = prop
Expand Down
1 change: 1 addition & 0 deletions driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
return &Config{
ClientConfig: &rpc.ClientConfig{
L1Endpoint: c.String(flags.L1WSEndpoint.Name),
L1BeaconEndpoint: c.String(flags.L1BeaconEndpoint.Name),
L2Endpoint: c.String(flags.L2WSEndpoint.Name),
L2CheckPoint: l2CheckPoint,
TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)),
Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Driver struct {
wg sync.WaitGroup
}

// InitFromCli New initializes the given driver instance based on the command line flags.
// InitFromCli initializes the given driver instance based on the command line flags.
func (d *Driver) InitFromCli(ctx context.Context, c *cli.Context) error {
cfg, err := NewConfigFromCliContext(c)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (s *DriverTestSuite) SetupTest() {
SgxAndPseZkevmTierFee: common.Big256,
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
L1BlockBuilderTip: common.Big0,
}))
s.p = p
}
Expand Down
47 changes: 47 additions & 0 deletions driver/txlist_fetcher/blob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package txlistdecoder

import (
"context"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/pkg/rpc"
)

type BlobFetcher struct {
rpc *rpc.Client
}

func NewBlobTxListFetcher(rpc *rpc.Client) *BlobFetcher {
return &BlobFetcher{rpc}
}

func (d *BlobFetcher) Fetch(
ctx context.Context,
tx *types.Transaction,
meta *bindings.TaikoDataBlockMetadata,
) ([]byte, error) {
if !meta.BlobUsed {
return nil, errBlobUnused
}

sidecars, err := d.rpc.GetBlobs(ctx, new(big.Int).SetUint64(meta.L1Height+1))
if err != nil {
return nil, err
}

log.Info("Fetch sidecars", "sidecars", sidecars)

for _, sidecar := range sidecars {
log.Info("Found sidecar", "KzgCommitment", sidecar.KzgCommitment, "blobHash", common.Bytes2Hex(meta.BlobHash[:]))

if sidecar.KzgCommitment == common.Bytes2Hex(meta.BlobHash[:]) {
return common.Hex2Bytes(sidecar.Blob), nil
}
}

return nil, errSidecarNotFound
}
23 changes: 23 additions & 0 deletions driver/txlist_fetcher/calldata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package txlistdecoder

import (
"context"

"github.com/ethereum/go-ethereum/core/types"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
)

type CalldataFetcher struct{}

func (d *CalldataFetcher) Fetch(
ctx context.Context,
tx *types.Transaction,
meta *bindings.TaikoDataBlockMetadata,
) ([]byte, error) {
if meta.BlobUsed {
return nil, errBlobUsed
}

return encoding.UnpackTxListBytes(tx.Data())
}
19 changes: 19 additions & 0 deletions driver/txlist_fetcher/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package txlistdecoder

import (
"context"
"errors"

"github.com/ethereum/go-ethereum/core/types"
"github.com/taikoxyz/taiko-client/bindings"
)

var (
errBlobUsed = errors.New("blob is used")
errBlobUnused = errors.New("blob is not used")
errSidecarNotFound = errors.New("sidecar not found")
)

type TxListFetcher interface {
Fetch(ctx context.Context, tx *types.Transaction, meta *bindings.TaikoDataBlockMetadata) ([]byte, error)
}
2 changes: 1 addition & 1 deletion internal/docker/docker_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ echo "L1_NODE_HTTP_ENDPOINT: $L1_NODE_HTTP_ENDPOINT"
echo "L1_NODE_WS_ENDPOINT: $L1_NODE_WS_ENDPOINT"
echo "L2_EXECUTION_ENGINE_HTTP_ENDPOINT: $L2_EXECUTION_ENGINE_HTTP_ENDPOINT"
echo "L2_EXECUTION_ENGINE_WS_ENDPOINT: $L2_EXECUTION_ENGINE_WS_ENDPOINT"
echo "L2_EXECUTION_ENGINE_AUTH_ENDPOINT: $L2_EXECUTION_ENGINE_AUTH_ENDPOINT"
echo "L2_EXECUTION_ENGINE_AUTH_ENDPOINT: $L2_EXECUTION_ENGINE_AUTH_ENDPOINT"
1 change: 0 additions & 1 deletion internal/docker/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

source scripts/common.sh

DOCKER_INIT_LIST=("create-beacon-chain-genesis" "geth-remove-db" "geth-genesis")
Expand Down
14 changes: 9 additions & 5 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,15 @@ type L2SyncProgress struct {

// isSyncing returns true if the L2 execution engine is syncing with L1.
func (p *L2SyncProgress) isSyncing() bool {
return p.SyncProgress != nil ||
p.CurrentBlockID == nil ||
p.HighestBlockID == nil ||
p.CurrentBlockID.Cmp(p.HighestBlockID) < 0
if p.SyncProgress == nil {
return false
}

if p.CurrentBlockID == nil || p.HighestBlockID == nil {
return true
}

return p.CurrentBlockID.Cmp(p.HighestBlockID) < 0
}

// L2ExecutionEngineSyncProgress fetches the sync progress of the given L2 execution engine.
Expand Down Expand Up @@ -764,7 +769,6 @@ func (c *Client) GetTiers(ctx context.Context) ([]*TierProviderTierWithID, error
// GetBlobs fetches blobs by the given slot from a L1 consensus client.
func (c *Client) GetBlobs(ctx context.Context, slot *big.Int) ([]*blob.Sidecar, error) {
var sidecars *blob.SidecarsResponse

resBytes, err := c.L1Beacon.Get(ctx, fmt.Sprintf(sidecarsRequestURL, slot))
if err != nil {
return nil, err
Expand Down
14 changes: 4 additions & 10 deletions pkg/txlistvalidator/tx_list_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"

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

// InvalidTxListReason represents a reason why a transactions list is invalid.
Expand Down Expand Up @@ -45,19 +43,15 @@ func NewTxListValidator(
// input data is valid.
func (v *TxListValidator) ValidateTxList(
blockID *big.Int,
proposeBlockTxInput []byte,
) (txListBytes []byte, hint InvalidTxListReason, txIdx int, err error) {
if txListBytes, err = encoding.UnpackTxListBytes(proposeBlockTxInput); err != nil {
return nil, HintNone, 0, err
}

txListBytes []byte,
) (hint InvalidTxListReason, txIdx int, err error) {
if len(txListBytes) == 0 {
return txListBytes, HintOK, 0, nil
return HintOK, 0, nil
}

hint, txIdx = v.isTxListValid(blockID, txListBytes)

return txListBytes, hint, txIdx, nil
return hint, txIdx, nil
}

// isTxListValid checks whether the transaction list is valid.
Expand Down
3 changes: 1 addition & 2 deletions pkg/txlistvalidator/tx_list_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func TestValidateTxList(t *testing.T) {
)

// Binary is not unpackable
txListBytes, _, _, err := v.ValidateTxList(common.Big0, randBytes(5))
require.Empty(t, txListBytes)
_, _, err := v.ValidateTxList(common.Big0, randBytes(5))
require.NotNil(t, err)
}

Expand Down
2 changes: 2 additions & 0 deletions proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
MaxTierFeePriceBumps uint64
IncludeParentMetaHash bool
BlobAllowed bool
L1BlockBuilderTip *big.Int
}

// NewConfigFromCliContext initializes a Config instance from
Expand Down Expand Up @@ -128,5 +129,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
MaxTierFeePriceBumps: c.Uint64(flags.MaxTierFeePriceBumps.Name),
IncludeParentMetaHash: c.Bool(flags.ProposeBlockIncludeParentMetaHash.Name),
BlobAllowed: c.Bool(flags.BlobAllowed.Name),
L1BlockBuilderTip: new(big.Int).SetUint64(c.Uint64(flags.L1BlockBuilderTip.Name)),
}, nil
}
6 changes: 4 additions & 2 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (p *Proposer) sendProposeBlockTxWithBlobHash(
ExtraData: rpc.StringToBytes32(p.ExtraData),
TxListByteOffset: common.Big0,
TxListByteSize: big.NewInt(int64(len(txListBytes))),
BlobHash: sideCar.BlobHashes()[0],
BlobHash: [32]byte{},
CacheBlobForReuse: false,
ParentMetaHash: parentMetaHash,
HookCalls: hookCalls,
Expand All @@ -405,6 +405,8 @@ func (p *Proposer) sendProposeBlockTxWithBlobHash(
return nil, err
}

log.Info("Tx", "proposeBlockTx", proposeTx, "type", proposeTx.Type())

return proposeTx, nil
}

Expand Down Expand Up @@ -461,7 +463,7 @@ func (p *Proposer) sendProposeBlockTx(
// TODO: flag for additional hook addresses and data.
hookInputData, err := encoding.EncodeAssignmentHookInput(&encoding.AssignmentHookInput{
Assignment: assignment,
Tip: common.Big0, // TODO: flag for tip
Tip: p.L1BlockBuilderTip,
})
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *ProposerTestSuite) SetupTest() {
MaxTierFeePriceBumps: 3,
ExtraData: "test",
BlobAllowed: true,
L1BlockBuilderTip: common.Big0,
}))

s.p = p
Expand Down
1 change: 1 addition & 0 deletions prover/proof_submitter/proof_submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() {
SgxAndPseZkevmTierFee: common.Big256,
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
L1BlockBuilderTip: common.Big0,
}))

s.proposer = prop
Expand Down
1 change: 1 addition & 0 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (s *ProverTestSuite) SetupTest() {
SgxAndPseZkevmTierFee: common.Big256,
MaxTierFeePriceBumps: 3,
TierFeePriceBump: common.Big2,
L1BlockBuilderTip: common.Big0,
}))

s.proposer = prop
Expand Down

0 comments on commit a90a152

Please sign in to comment.