Skip to content

Commit

Permalink
sequencer log (0xPolygonHermez#1052)
Browse files Browse the repository at this point in the history
* log fix sequencer

* getLastestBlockTimestamp
  • Loading branch information
ARR552 authored Aug 18, 2022
1 parent ffdd7f1 commit cdbf8f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ func (etherMan *Client) EthBlockByNumber(ctx context.Context, blockNumber uint64
return block, nil
}

// GetLastTimestamp function allows to retrieve the lastTimestamp value in the smc
func (etherMan *Client) GetLastTimestamp() (uint64, error) {
// GetLastBatchTimestamp function allows to retrieve the lastTimestamp value in the smc
func (etherMan *Client) GetLastBatchTimestamp() (uint64, error) {
return etherMan.PoE.LastTimestamp(&bind.CallOpts{Pending: false})
}

Expand All @@ -572,6 +572,15 @@ func (etherMan *Client) GetLatestBlockNumber(ctx context.Context) (uint64, error
return header.Number.Uint64(), nil
}

// GetLatestBlockTimestamp gets the latest block timestamp from the ethereum
func (etherMan *Client) GetLatestBlockTimestamp(ctx context.Context) (uint64, error) {
header, err := etherMan.EtherClient.HeaderByNumber(ctx, nil)
if err != nil || header == nil {
return 0, err
}
return header.Time, nil
}

// GetLatestVerifiedBatchNum gets latest verified batch from ethereum
func (etherMan *Client) GetLatestVerifiedBatchNum() (uint64, error) {
return etherMan.PoE.LastVerifiedBatch(&bind.CallOpts{Pending: false})
Expand Down
3 changes: 2 additions & 1 deletion sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type etherman interface {
TrustedSequencer() (common.Address, error)
GetLatestBatchNumber() (uint64, error)
GetLatestBlockNumber(ctx context.Context) (uint64, error)
GetLastTimestamp() (uint64, error)
GetLastBatchTimestamp() (uint64, error)
GetLatestBlockTimestamp(ctx context.Context) (uint64, error)
}

// stateInterface gathers the methods required to interact with the state.
Expand Down
12 changes: 8 additions & 4 deletions sequencer/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *Sequencer) getSequencesToSend(ctx context.Context) ([]types.Sequence, e
// Check if can be send
estimatedGas, err = s.etherman.EstimateGasSequenceBatches(sequences)
if err != nil {
sequences, err = s.handleEstimateGasSendSequenceErr(sequences, currentBatchNumToSequence, err)
sequences, err = s.handleEstimateGasSendSequenceErr(ctx, sequences, currentBatchNumToSequence, err)
if sequences != nil {
// Handling the error gracefully, re-processing the sequence as a sanity check
_, err = s.etherman.EstimateGasSequenceBatches(sequences)
Expand Down Expand Up @@ -122,6 +122,7 @@ func (s *Sequencer) getSequencesToSend(ctx context.Context) ([]types.Sequence, e
// sequence, nil: handled gracefully. Potentially manipulating the sequences
// nil, nil: a situation that requires waiting
func (s *Sequencer) handleEstimateGasSendSequenceErr(
ctx context.Context,
sequences []types.Sequence,
currentBatchNumToSequence uint64,
err error,
Expand Down Expand Up @@ -153,7 +154,7 @@ func (s *Sequencer) handleEstimateGasSendSequenceErr(
// an error regarding timestamp verification, this must be handled
if strings.Contains(err.Error(), errTimestampMustBeInsideRange) {
// query the sc about the value of its lastTimestamp variable
lastTimestamp, err := s.etherman.GetLastTimestamp()
lastTimestamp, err := s.etherman.GetLastBatchTimestamp()
if err != nil {
return nil, err
}
Expand All @@ -165,8 +166,11 @@ func (s *Sequencer) handleEstimateGasSendSequenceErr(
}
lastTimestamp = uint64(seq.Timestamp)
}

log.Debug("block.timestamp is greater than seq.Timestamp. A new block must be mined in L1 before the gas can be estimated.")
blockTimestamp, err := s.etherman.GetLatestBlockTimestamp(ctx)
if err != nil {
log.Error("error getting block timestamp: ", err)
}
log.Debugf("block.timestamp: %d is smaller than seq.Timestamp: %d. A new block must be mined in L1 before the gas can be estimated.", blockTimestamp, sequences[0].Timestamp)
return nil, nil
}

Expand Down

0 comments on commit cdbf8f2

Please sign in to comment.