Skip to content

Commit

Permalink
fix(vald): panic when confirming gateway txs and tx is not finalized (#…
Browse files Browse the repository at this point in the history
…2108)

* fix(vald): panic when confirming gateway txs and tx is not finalized

* fix log
  • Loading branch information
fish-sammy authored Feb 23, 2024
1 parent 1bb5257 commit 0d6928d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions vald/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var (
TokenSentSig = crypto.Keccak256Hash([]byte("TokenSent(address,string,string,string,uint256)"))
)

// NotFinalized is returned when a transaction is not finalized
var NotFinalized = goerrors.New("not finalized")
// ErrNotFinalized is returned when a transaction is not finalized
var ErrNotFinalized = goerrors.New("not finalized")

// Mgr manages all communication with Ethereum
type Mgr struct {
Expand Down Expand Up @@ -302,8 +302,8 @@ func (mgr Mgr) ProcessGatewayTxsConfirmation(event *types.ConfirmGatewayTxsStart
events := mgr.processGatewayTxLogs(event.Chain, event.GatewayAddress, result.Ok().Logs)
logger.Infof("broadcasting vote %v", events)
votes = append(votes, voteTypes.NewVoteRequest(mgr.proxy, pollID, types.NewVoteEvents(event.Chain, events...)))
case NotFinalized:
logger.Debug(fmt.Sprintf("transaction %s in block %s not finalized", txID.Hex(), result.Ok().BlockNumber.String()))
case ErrNotFinalized:
logger.Debug(fmt.Sprintf("transaction %s not finalized", txID.Hex()))
logger.Infof("broadcasting empty vote due to error: %s", result.Err().Error())
votes = append(votes, voteTypes.NewVoteRequest(mgr.proxy, pollID, types.NewVoteEvents(event.Chain)))
case ethereum.NotFound:
Expand Down Expand Up @@ -502,7 +502,7 @@ func (mgr Mgr) GetTxReceiptsIfFinalized(chain nexus.ChainName, txIDs []common.Ha
}

if !isFinalized {
return rs.FromErr[*geth.Receipt](NotFinalized)
return rs.FromErr[*geth.Receipt](ErrNotFinalized)
}

return rs.FromOk(receipt)
Expand Down
2 changes: 1 addition & 1 deletion vald/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ func TestMgr_GetTxReceiptsIfFinalized(t *testing.T) {
notFinalized := receipts[len(txHashes)/2:]

assert.True(t, slices.All(finalized, func(result results.Result[*geth.Receipt]) bool { return result.Err() == nil }))
assert.True(t, slices.All(notFinalized, func(result results.Result[*geth.Receipt]) bool { return result.Err() == evm.NotFinalized }))
assert.True(t, slices.All(notFinalized, func(result results.Result[*geth.Receipt]) bool { return result.Err() == evm.ErrNotFinalized }))
}),
).
Run(t, 5)
Expand Down

0 comments on commit 0d6928d

Please sign in to comment.