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)
  • Loading branch information
agnusmor authored Jul 18, 2024
1 parent 7aa74dc commit 19beaa9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 33 deletions.
7 changes: 4 additions & 3 deletions ethtxmanager/ethtxmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,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
4 changes: 0 additions & 4 deletions state/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const (
FORKID_ELDERBERRY = 8
// FORKID_9 is the fork id 9
FORKID_9 = 9
// FORKID_10 is the fork id 10
FORKID_10 = 10
// FORKID_11 is the fork id 11
FORKID_11 = 11
)

// ForkIDInterval is a fork id interval
Expand Down
6 changes: 1 addition & 5 deletions synchronizer/actions/forksids.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ const (
ForkIDElderberry = ForkIdType(8) //nolint:gomnd
// ForkID9 is the forkId for 9
ForkID9 = ForkIdType(9) //nolint:gomnd
// ForkID10 is the forkId for 10 (support more counters)
ForkID10 = ForkIdType(10) //nolint:gomnd
// ForkID11 is the forkId for 11 (support even more counters)
ForkID11 = ForkIdType(11) //nolint:gomnd
)

var (
Expand All @@ -26,7 +22,7 @@ var (
ForksIdAll = []ForkIdType{WildcardForkId}

// ForksIdOnlyElderberry support only elderberry forkId
ForksIdOnlyElderberry = []ForkIdType{ForkIDElderberry, ForkID9, ForkID10, ForkID11}
ForksIdOnlyElderberry = []ForkIdType{ForkIDElderberry, ForkID9}

// ForksIdOnlyEtrog support only etrog forkId
ForksIdOnlyEtrog = []ForkIdType{ForkIDEtrog}
Expand Down

0 comments on commit 19beaa9

Please sign in to comment.