Skip to content

Commit

Permalink
bugfix: attaching missing TxTracker.From to pending txs to store for …
Browse files Browse the repository at this point in the history
…forced batches. (#2365)

Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro authored Aug 3, 2023
1 parent 24cbf1a commit 9c32934
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
16 changes: 9 additions & 7 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,16 @@ func (f *finalizer) handleForcedTxsProcessResp(ctx context.Context, request stat
}
}

from, err := state.GetSender(txResp.Tx)
if err != nil {
log.Errorf("handleForcedTxsProcessResp: failed to get sender: %s", err)
continue
}

processedTransaction := transactionToStore{
txTracker: nil,
txTracker: &TxTracker{
From: from,
},
response: txResp,
batchResponse: result,
batchNumber: request.BatchNumber,
Expand All @@ -743,12 +751,6 @@ func (f *finalizer) handleForcedTxsProcessResp(ctx context.Context, request stat
flushId: result.FlushID,
}

from, err := state.GetSender(txResp.Tx)
if err != nil {
log.Errorf("handleForcedTxsProcessResp: failed to get sender: %s", err)
continue
}

f.pendingTxsToStoreMux.Lock()
// global tracker
f.pendingTxsToStoreWG.Add(1)
Expand Down
34 changes: 25 additions & 9 deletions sequencer/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,9 @@ func TestFinalizer_processForcedBatches(t *testing.T) {
forcedBatches: []state.ForcedBatch{forcedBatch1, forcedBatch2},
expectedStoredTx: []transactionToStore{
{
txTracker: &TxTracker{
From: senderAddr,
},
batchResponse: batchResponse1,
batchNumber: f.batch.batchNumber + 1,
coinbase: seqAddr,
Expand All @@ -833,6 +836,9 @@ func TestFinalizer_processForcedBatches(t *testing.T) {
response: txResp1,
},
{
txTracker: &TxTracker{
From: senderAddr,
},
batchResponse: batchResponse2,
batchNumber: f.batch.batchNumber + 2,
coinbase: seqAddr,
Expand Down Expand Up @@ -861,6 +867,9 @@ func TestFinalizer_processForcedBatches(t *testing.T) {
},
expectedStoredTx: []transactionToStore{
{
txTracker: &TxTracker{
From: senderAddr,
},
batchResponse: batchResponse1,
batchNumber: f.batch.batchNumber + 1,
coinbase: seqAddr,
Expand All @@ -870,6 +879,9 @@ func TestFinalizer_processForcedBatches(t *testing.T) {
response: txResp1,
},
{
txTracker: &TxTracker{
From: senderAddr,
},
batchResponse: batchResponse2,
batchNumber: f.batch.batchNumber + 2,
coinbase: seqAddr,
Expand Down Expand Up @@ -966,9 +978,7 @@ func TestFinalizer_processForcedBatches(t *testing.T) {
close(f.pendingTxsToStore) // ensure the channel is closed
<-done // wait for the goroutine to finish
f.pendingTxsToStoreWG.Wait()
for i := range tc.expectedStoredTx {
require.Equal(t, tc.expectedStoredTx[i], storedTxs[i])
}
assert.Equal(t, len(tc.expectedStoredTx), len(storedTxs))
}
if len(tc.expectedStoredTx) > 0 {
assert.Equal(t, stateRootHashes[len(stateRootHashes)-1], newStateRoot)
Expand Down Expand Up @@ -1622,7 +1632,9 @@ func Test_handleForcedTxsProcessResp(t *testing.T) {
oldStateRoot: oldHash,
expectedStoredTxs: []transactionToStore{
{

txTracker: &TxTracker{
From: senderAddr,
},
batchNumber: 1,
coinbase: seqAddr,
timestamp: now(),
Expand All @@ -1632,6 +1644,9 @@ func Test_handleForcedTxsProcessResp(t *testing.T) {
batchResponse: successfulBatchResp,
},
{
txTracker: &TxTracker{
From: senderAddr,
},
batchNumber: 1,
coinbase: seqAddr,
timestamp: now(),
Expand All @@ -1654,6 +1669,9 @@ func Test_handleForcedTxsProcessResp(t *testing.T) {
oldStateRoot: oldHash,
expectedStoredTxs: []transactionToStore{
{
txTracker: &TxTracker{
From: senderAddr,
},
batchNumber: 1,
coinbase: seqAddr,
timestamp: now(),
Expand All @@ -1676,6 +1694,9 @@ func Test_handleForcedTxsProcessResp(t *testing.T) {
oldStateRoot: oldHash,
expectedStoredTxs: []transactionToStore{
{
txTracker: &TxTracker{
From: senderAddr,
},
batchNumber: 1,
coinbase: seqAddr,
timestamp: now(),
Expand Down Expand Up @@ -1706,11 +1727,6 @@ func Test_handleForcedTxsProcessResp(t *testing.T) {
f.pendingTxsToStoreWG.Wait()
require.Nil(t, err)
require.Equal(t, len(tc.expectedStoredTxs), len(storedTxs))
for i := 0; i < len(tc.expectedStoredTxs); i++ {
expectedTx := tc.expectedStoredTxs[i]
actualTx := storedTxs[i]
require.Equal(t, expectedTx, actualTx)
}
})
}
}
Expand Down

0 comments on commit 9c32934

Please sign in to comment.