Skip to content

Commit

Permalink
Add mined l1blocknumber to MonitoredTxResult. Undo forkid10 and forki…
Browse files Browse the repository at this point in the history
…d11 changes (#3734) (#3758)
  • Loading branch information
agnusmor authored Aug 9, 2024
1 parent 07c3182 commit 9b315a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
7 changes: 4 additions & 3 deletions ethtxmanager/ethtxmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ func (c *Client) buildResult(ctx context.Context, mTx monitoredTx) (MonitoredTxR
}

result := MonitoredTxResult{
ID: mTx.id,
Status: mTx.status,
Txs: txs,
ID: mTx.id,
Status: mTx.status,
BlockNumber: mTx.blockNumber,
Txs: txs,
}

return result, nil
Expand Down
7 changes: 4 additions & 3 deletions ethtxmanager/monitoredtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ func (mTx *monitoredTx) blockNumberU64Ptr() *uint64 {

// MonitoredTxResult represents the result of a execution of a monitored tx
type MonitoredTxResult struct {
ID string
Status MonitoredTxStatus
Txs map[common.Hash]TxResult
ID string
Status MonitoredTxStatus
BlockNumber *big.Int
Txs map[common.Hash]TxResult
}

// TxResult represents the result of a execution of a ethereum transaction in the block chain
Expand Down
23 changes: 5 additions & 18 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/0xPolygonHermez/zkevm-node/event"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/jackc/pgx/v4"
)
Expand Down Expand Up @@ -97,33 +96,21 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) {
s.ethTxManager.ProcessPendingMonitoredTxs(ctx, ethTxManagerOwner, func(result ethtxmanager.MonitoredTxResult, dbTx pgx.Tx) {
if result.Status == ethtxmanager.MonitoredTxStatusConfirmed {
if len(result.Txs) > 0 {
var txL1BlockNumber uint64
var txHash common.Hash
receiptFound := false
for _, tx := range result.Txs {
if tx.Receipt != nil {
txL1BlockNumber = tx.Receipt.BlockNumber.Uint64()
txHash = tx.Tx.Hash()
receiptFound = true
break
}
}

if !receiptFound {
s.halt(ctx, fmt.Errorf("monitored tx %s for sequence [%d-%d] is confirmed but doesn't have a receipt", result.ID, s.lastSequenceInitialBatch, s.lastSequenceEndBatch))
if result.BlockNumber == nil {
s.halt(ctx, fmt.Errorf("monitored tx %s for sequence [%d-%d] is confirmed but doesn't have L1 block number where tx was mined", result.ID, s.lastSequenceInitialBatch, s.lastSequenceEndBatch))
}

// wait L1 confirmation blocks
log.Infof("waiting %d L1 block confirmations for sequence [%d-%d], L1 block: %d, tx: %s",
s.cfg.SequenceL1BlockConfirmations, s.lastSequenceInitialBatch, s.lastSequenceEndBatch, txL1BlockNumber, txHash)
log.Infof("waiting %d L1 block confirmations for sequence [%d-%d], L1 block: %d",
s.cfg.SequenceL1BlockConfirmations, s.lastSequenceInitialBatch, s.lastSequenceEndBatch, result.BlockNumber)
for {
lastL1BlockHeader, err := s.etherman.GetLatestBlockHeader(ctx)
if err != nil {
log.Errorf("failed to get last L1 block number, err: %v", err)
} else {
lastL1BlockNumber := lastL1BlockHeader.Number.Uint64()

if lastL1BlockNumber >= txL1BlockNumber+s.cfg.SequenceL1BlockConfirmations {
if lastL1BlockNumber >= result.BlockNumber.Uint64()+s.cfg.SequenceL1BlockConfirmations {
log.Infof("continuing, last L1 block: %d", lastL1BlockNumber)
break
}
Expand Down

0 comments on commit 9b315a1

Please sign in to comment.