Commit 0f012ed9 authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

fix: correct cancel nonce check (#2395)

parent 0b244e9b
...@@ -224,7 +224,9 @@ func (tm *transactionMonitor) checkPending(block uint64) error { ...@@ -224,7 +224,9 @@ func (tm *transactionMonitor) checkPending(block uint64) error {
} }
for _, watch := range potentiallyCancelledTxs { for _, watch := range potentiallyCancelledTxs {
if watch.nonce <= oldNonce { // oldNonce is the nonce of the next tx that could have been included
// if this was already larger in the past our transaction becomes impossible
if watch.nonce < oldNonce {
cancelledTxs = append(cancelledTxs, watch) cancelledTxs = append(cancelledTxs, watch)
} }
} }
......
...@@ -253,6 +253,84 @@ func TestMonitorWatchTransaction(t *testing.T) { ...@@ -253,6 +253,84 @@ func TestMonitorWatchTransaction(t *testing.T) {
} }
}) })
t.Run("single transaction no confirm", func(t *testing.T) {
txHash2 := common.HexToHash("bbbb")
monitor := transaction.NewMonitor(
logger,
backendsimulation.New(
backendsimulation.WithBlocks(
backendsimulation.Block{
Number: 0,
},
backendsimulation.Block{
Number: 1,
NoncesAt: map[backendsimulation.AccountAtKey]uint64{
{
BlockNumber: 1,
Account: sender,
}: nonce,
},
},
backendsimulation.Block{
Number: 1 + cancellationDepth,
NoncesAt: map[backendsimulation.AccountAtKey]uint64{
{
BlockNumber: 1,
Account: sender,
}: nonce,
{
BlockNumber: 1 + cancellationDepth,
Account: sender,
}: nonce + 1,
},
},
backendsimulation.Block{
Number: 1 + cancellationDepth + 1,
Receipts: map[common.Hash]*types.Receipt{
txHash2: {TxHash: txHash2},
},
NoncesAt: map[backendsimulation.AccountAtKey]uint64{
{
BlockNumber: 1 + cancellationDepth + 1,
Account: sender,
}: nonce + 1,
},
},
),
),
sender,
pollingInterval,
cancellationDepth,
)
receiptC, errC, err := monitor.WatchTransaction(txHash, nonce)
if err != nil {
t.Fatal(err)
}
receiptC2, errC2, err := monitor.WatchTransaction(txHash2, nonce)
if err != nil {
t.Fatal(err)
}
select {
case <-receiptC:
t.Fatal("got receipt")
case err := <-errC:
t.Fatal(err)
case <-receiptC2:
case err := <-errC2:
t.Fatal(err)
case <-time.After(1 * time.Second):
t.Fatal("timeout")
}
err = monitor.Close()
if err != nil {
t.Fatal(err)
}
})
t.Run("shutdown while waiting", func(t *testing.T) { t.Run("shutdown while waiting", func(t *testing.T) {
monitor := transaction.NewMonitor( monitor := transaction.NewMonitor(
logger, logger,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment