-
Notifications
You must be signed in to change notification settings - Fork 105
/
gateway_tx_confirmation.go
118 lines (99 loc) · 3.59 KB
/
gateway_tx_confirmation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package evm
import (
"bytes"
"context"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
geth "github.com/ethereum/go-ethereum/core/types"
"github.com/axelarnetwork/axelar-core/x/evm/types"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
voteTypes "github.com/axelarnetwork/axelar-core/x/vote/types"
)
// ProcessGatewayTxConfirmation votes on the correctness of an EVM chain gateway's transactions
func (mgr Mgr) ProcessGatewayTxConfirmation(event *types.ConfirmGatewayTxStarted) error {
if !mgr.isParticipantOf(event.Participants) {
mgr.logger("pollID", event.PollID).Debug("ignoring gateway tx confirmation poll: not a participant")
return nil
}
var vote *voteTypes.VoteRequest
txReceipt, err := mgr.GetTxReceiptIfFinalized(event.Chain, common.Hash(event.TxID), event.ConfirmationHeight)
if err != nil {
return err
}
if txReceipt.Err() != nil {
vote = voteTypes.NewVoteRequest(mgr.proxy, event.PollID, types.NewVoteEvents(event.Chain))
mgr.logger().Infof("broadcasting empty vote for poll %s: %s", event.PollID.String(), txReceipt.Err().Error())
} else {
events := mgr.processGatewayTxLogs(event.Chain, event.GatewayAddress, txReceipt.Ok().Logs)
vote = voteTypes.NewVoteRequest(mgr.proxy, event.PollID, types.NewVoteEvents(event.Chain, events...))
mgr.logger().Infof("broadcasting vote %v for poll %s", events, event.PollID.String())
}
_, err = mgr.broadcaster.Broadcast(context.TODO(), vote)
return err
}
// extract receipt processing from ProcessGatewayTxConfirmation, so that it can be used in ProcessGatewayTxsConfirmation
func (mgr Mgr) processGatewayTxLogs(chain nexus.ChainName, gatewayAddress types.Address, logs []*geth.Log) []types.Event {
var events []types.Event
for i, txlog := range logs {
if !bytes.Equal(gatewayAddress.Bytes(), txlog.Address.Bytes()) {
continue
}
switch txlog.Topics[0] {
case ContractCallSig:
gatewayEvent, err := DecodeEventContractCall(txlog)
if err != nil {
mgr.logger().Debug(sdkerrors.Wrap(err, "decode event ContractCall failed").Error())
continue
}
if err := gatewayEvent.ValidateBasic(); err != nil {
mgr.logger().Debug(sdkerrors.Wrap(err, "invalid event ContractCall").Error())
continue
}
events = append(events, types.Event{
Chain: chain,
TxID: types.Hash(txlog.TxHash),
Index: uint64(i),
Event: &types.Event_ContractCall{
ContractCall: &gatewayEvent,
},
})
case ContractCallWithTokenSig:
gatewayEvent, err := DecodeEventContractCallWithToken(txlog)
if err != nil {
mgr.logger().Debug(sdkerrors.Wrap(err, "decode event ContractCallWithToken failed").Error())
continue
}
if err := gatewayEvent.ValidateBasic(); err != nil {
mgr.logger().Debug(sdkerrors.Wrap(err, "invalid event ContractCallWithToken").Error())
continue
}
events = append(events, types.Event{
Chain: chain,
TxID: types.Hash(txlog.TxHash),
Index: uint64(i),
Event: &types.Event_ContractCallWithToken{
ContractCallWithToken: &gatewayEvent,
},
})
case TokenSentSig:
gatewayEvent, err := DecodeEventTokenSent(txlog)
if err != nil {
mgr.logger().Debug(sdkerrors.Wrap(err, "decode event TokenSent failed").Error())
}
if err := gatewayEvent.ValidateBasic(); err != nil {
mgr.logger().Debug(sdkerrors.Wrap(err, "invalid event TokenSent").Error())
continue
}
events = append(events, types.Event{
Chain: chain,
TxID: types.Hash(txlog.TxHash),
Index: uint64(i),
Event: &types.Event_TokenSent{
TokenSent: &gatewayEvent,
},
})
default:
}
}
return events
}