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

Commit

Permalink
fix(driver): use protocol's last valid parent block as the throwaway …
Browse files Browse the repository at this point in the history
…block's pre-state (#102)
  • Loading branch information
davidtaikocha authored Dec 24, 2022
1 parent 64c1d98 commit fb7aabb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
73 changes: 31 additions & 42 deletions driver/block_inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,17 @@ func (s *L2ChainSyncer) onBlockProposed(
return nil
}

if event.Id.Uint64() < s.state.getHeadBlockID().Uint64() {
log.Info(
"Pending proposed block to sync",
"L1Height", event.Raw.BlockNumber,
"L1Hash", event.Raw.BlockHash,
"BlockID", event.Id,
)
} else {
log.Info(
"📝 New proposed block",
"L1Height", event.Raw.BlockNumber,
"L1Hash", event.Raw.BlockHash,
"BlockID", event.Id,
)
}

// Get the original TaikoL1.proposeBlock transaction.
tx, err := s.rpc.L1.TransactionInBlock(ctx, event.Raw.BlockHash, event.Raw.TxIndex)
if err != nil {
return fmt.Errorf("failed to fetch original TaikoL1.proposeBlock transaction: %w", err)
}

// Check whether the transactions list is valid.
txListBytes, hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.Id, tx.Data())
if err != nil {
return fmt.Errorf("failed to validate transactions list: %w", err)
}

log.Info(
"Validate transactions list",
"blockID", event.Id,
"hint", hint,
"invalidTxIndex", invalidTxIndex,
"New BlockProposed event",
"L1Height", event.Raw.BlockNumber,
"L1Hash", event.Raw.BlockHash,
"BlockID", event.Id,
)

// Fetch the L2 parent block.
var (
parent *types.Header
throwaway = hint != txListValidator.HintOK
parent *types.Header
err error
)
if s.syncProgressTracker.Triggered() {
// Already synced through beacon sync, just skip this event.
Expand All @@ -81,12 +53,7 @@ func (s *L2ChainSyncer) onBlockProposed(

parent, err = s.rpc.L2.HeaderByHash(ctx, s.syncProgressTracker.LastSyncedVerifiedBlockHash())
} else {
if throwaway {
// NOTE: for throwaway blocks, use genesis block as the pre-state now, which may change in future.
parent, err = s.rpc.L2.HeaderByNumber(s.ctx, common.Big0)
} else {
parent, err = s.rpc.L2ParentByBlockId(ctx, event.Id)
}
parent, err = s.rpc.L2ParentByBlockId(ctx, event.Id)
}

if err != nil {
Expand All @@ -95,12 +62,34 @@ func (s *L2ChainSyncer) onBlockProposed(

log.Debug("Parent block", "height", parent.Number, "hash", parent.Hash())

tx, err := s.rpc.L1.TransactionInBlock(
ctx,
event.Raw.BlockHash,
event.Raw.TxIndex,
)
if err != nil {
return fmt.Errorf("failed to fetch original TaikoL1.proposeBlock transaction: %w", err)
}

// Check whether the transactions list is valid.
txListBytes, hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.Id, tx.Data())
if err != nil {
return fmt.Errorf("failed to validate transactions list: %w", err)
}

log.Info(
"Validate transactions list",
"blockID", event.Id,
"hint", hint,
"invalidTxIndex", invalidTxIndex,
)

l1Origin := &rawdb.L1Origin{
BlockID: event.Id,
L2BlockHash: common.Hash{}, // Will be set by taiko-geth.
L1BlockHeight: new(big.Int).SetUint64(event.Raw.BlockNumber),
L1BlockHash: event.Raw.BlockHash,
Throwaway: throwaway,
Throwaway: hint != txListValidator.HintOK,
}

if event.Meta.Timestamp > uint64(time.Now().Unix()) {
Expand Down Expand Up @@ -255,7 +244,7 @@ func (s *L2ChainSyncer) insertThrowAwayBlock(
txListBytes []byte,
l1Origin *rawdb.L1Origin,
) (*beacon.ExecutableDataV1, error, error) {
log.Info(
log.Debug(
"Try to insert a new L2 throwaway block",
"parentHash", parent.Hash(),
"headBlockID", headBlockID,
Expand Down
9 changes: 8 additions & 1 deletion prover/invalid_block_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (p *Prover) proveBlockInvalid(
return err
}

log.Debug("Throwaway block", "header", throwAwayBlock.Header())
log.Debug("Throwaway block", "height", throwAwayBlock.Header().Number, "hash", throwAwayBlock.Header().Hash())

// Request proof.
proofOpts := &producer.ProofRequestOptions{
Expand Down Expand Up @@ -144,6 +144,9 @@ func (p *Prover) submitInvalidBlockProof(

var isUnretryableError bool
if err := backoff.Retry(func() error {
if p.ctx.Err() != nil {
return nil
}
sendTx := func() (*types.Transaction, error) {
p.submitProofTxMutex.Lock()
defer p.submitProofTxMutex.Unlock()
Expand Down Expand Up @@ -172,6 +175,10 @@ func (p *Prover) submitInvalidBlockProof(
return fmt.Errorf("failed to send TaikoL1.proveBlockInvalid transaction: %w", err)
}

if p.ctx.Err() != nil {
return p.ctx.Err()
}

if isUnretryableError {
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions prover/valid_block_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func (p *Prover) submitValidBlockProof(ctx context.Context, proofWithHeader *pro

var isUnretryableError bool
if err := backoff.Retry(func() error {
if p.ctx.Err() != nil {
return nil
}
sendTx := func() (*types.Transaction, error) {
p.submitProofTxMutex.Lock()
defer p.submitProofTxMutex.Unlock()
Expand Down Expand Up @@ -180,6 +183,10 @@ func (p *Prover) submitValidBlockProof(ctx context.Context, proofWithHeader *pro
return fmt.Errorf("failed to send TaikoL1.proveBlock transaction: %w", err)
}

if p.ctx.Err() != nil {
return p.ctx.Err()
}

if isUnretryableError {
return nil
}
Expand Down

0 comments on commit fb7aabb

Please sign in to comment.