Skip to content

Commit 72fa419

Browse files
TestProcessor_BackwardLET, backward LET on empty bridge table
1 parent 2e39f39 commit 72fa419

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

bridgesync/processor.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,12 @@ func (p *processor) ProcessBlock(ctx context.Context, block sync.Block) error {
14641464
return fmt.Errorf("failed to convert new deposit count to uint64: %w", err)
14651465
}
14661466

1467+
leafIndex, err := aggkitcommon.SafeUint32(newDepositCountU64)
1468+
if err != nil {
1469+
return fmt.Errorf("failed to convert new deposit count (uint64) to leaf index (uint32): %w",
1470+
err)
1471+
}
1472+
14671473
// 1. remove all the bridges whose deposit_count is greater than the one captured by the BackwardLET event
14681474
deleteBridges := fmt.Sprintf("DELETE from %s WHERE deposit_count > $1", bridgeTableName)
14691475
_, err = tx.Exec(deleteBridges, newDepositCountU64)
@@ -1473,11 +1479,6 @@ func (p *processor) ProcessBlock(ctx context.Context, block sync.Block) error {
14731479
}
14741480

14751481
// 2. remove all leafs from the exit tree with indices greater than leafIndex in the exit tree
1476-
leafIndex, err := aggkitcommon.SafeUint32(newDepositCountU64)
1477-
if err != nil {
1478-
return fmt.Errorf("failed to convert new deposit count (uint64) to leaf index (uint32): %w",
1479-
err)
1480-
}
14811482
if err := p.exitTree.BackwardToIndex(ctx, tx, leafIndex); err != nil {
14821483
p.log.Errorf("failed to backward local exit tree to leaf index %d (deposit count: %d)",
14831484
leafIndex, newDepositCountU64)

bridgesync/processor_test.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5377,7 +5377,7 @@ func TestProcessor_BackwardLET(t *testing.T) {
53775377
collectExpectedBridgesUpTo := func(t *testing.T, blocks []sync.Block, targetDepositCount uint32) []Bridge {
53785378
t.Helper()
53795379

5380-
var bridges []Bridge
5380+
bridges := make([]Bridge, 0)
53815381
for _, b := range blocks {
53825382
for _, e := range b.Events {
53835383
evt, ok := e.(Event)
@@ -5498,6 +5498,63 @@ func TestProcessor_BackwardLET(t *testing.T) {
54985498
},
54995499
targetDepositCount: 3,
55005500
},
5501+
{
5502+
name: "backward let on empty bridge table",
5503+
setupBlocks: func() []sync.Block {
5504+
return []sync.Block{
5505+
{
5506+
Num: 1,
5507+
Hash: common.HexToHash("0x1"),
5508+
Events: []any{
5509+
Event{BackwardLET: &BackwardLET{
5510+
BlockNum: 1,
5511+
BlockPos: 0,
5512+
PreviousDepositCount: big.NewInt(6),
5513+
NewDepositCount: big.NewInt(3),
5514+
}},
5515+
},
5516+
}}
5517+
},
5518+
targetDepositCount: 0,
5519+
},
5520+
{
5521+
name: "backward let invalid new deposit count (outside of uint64 range)",
5522+
setupBlocks: func() []sync.Block {
5523+
return []sync.Block{
5524+
{
5525+
Num: 1,
5526+
Hash: common.HexToHash("0x1"),
5527+
Events: []any{
5528+
Event{BackwardLET: &BackwardLET{
5529+
BlockNum: 1,
5530+
BlockPos: 0,
5531+
PreviousDepositCount: big.NewInt(0),
5532+
NewDepositCount: big.NewInt(-3),
5533+
}},
5534+
},
5535+
}}
5536+
},
5537+
processBlockErrMsg: "failed to convert new deposit count to uint64",
5538+
},
5539+
{
5540+
name: "backward let invalid new deposit count (outside of uint32 range)",
5541+
setupBlocks: func() []sync.Block {
5542+
return []sync.Block{
5543+
{
5544+
Num: 1,
5545+
Hash: common.HexToHash("0x1"),
5546+
Events: []any{
5547+
Event{BackwardLET: &BackwardLET{
5548+
BlockNum: 1,
5549+
BlockPos: 0,
5550+
PreviousDepositCount: big.NewInt(0),
5551+
NewDepositCount: big.NewInt(4294967296),
5552+
}},
5553+
},
5554+
}}
5555+
},
5556+
processBlockErrMsg: "failed to convert new deposit count (uint64) to leaf index (uint32)",
5557+
},
55015558
{
55025559
name: "backward let after a couple of bridges + reorg backward let",
55035560
setupBlocks: func() []sync.Block {

0 commit comments

Comments
 (0)