Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong state root when prevlastbatch & lastbatch are empty + restart #2028

Merged
merged 5 commits into from
Apr 19, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions sequencer/dbmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,26 @@ func (d *dbManager) GetWIPBatch(ctx context.Context) (*WipBatch, error) {
if err != nil {
return nil, err
}

lastBatch.Transactions = lastBatchTxs

lastStateRoot, err := d.state.GetLastStateRoot(ctx, dbTx)
if err != nil {
return nil, err
var prevLastBatchTxs []types.Transaction
if previousLastBatch != nil {
prevLastBatchTxs, _, err = state.DecodeTxs(previousLastBatch.BatchL2Data)
if err != nil {
return nil, err
}
}

var lastStateRoot common.Hash
// If the last two batches has no txs, the stateRoot can not be retrieve from the l2block because there is no tx.
ARR552 marked this conversation as resolved.
Show resolved Hide resolved
// In this case, the stateRoot must be get from the previousLastBatch
ARR552 marked this conversation as resolved.
Show resolved Hide resolved
if len(lastBatchTxs) == 0 && previousLastBatch != nil && len(prevLastBatchTxs) == 0 {
lastStateRoot = previousLastBatch.StateRoot
} else {
lastStateRoot, err = d.state.GetLastStateRoot(ctx, dbTx)
if err != nil {
return nil, err
}
}

wipBatch := &WipBatch{
Expand Down
Loading