-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support timeout handling in chain provider #57
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,13 @@ import ( | |
|
||
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" | ||
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
host "github.com/cosmos/ibc-go/v8/modules/core/24-host" | ||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/hyperledger-labs/yui-relayer/core" | ||
"github.com/hyperledger-labs/yui-relayer/log" | ||
|
||
|
@@ -48,6 +50,38 @@ func init() { | |
abiChannelUpgradeOpen = abiIBCHandler.Events["ChannelUpgradeOpen"] | ||
} | ||
|
||
// filterPacketsWithActiveCommitment filters packets with non-zero packet commitments | ||
func (chain *Chain) filterPacketsWithActiveCommitment(ctx core.QueryContext, packets core.PacketInfoList) (core.PacketInfoList, error) { | ||
|
||
var activePackets core.PacketInfoList | ||
|
||
for _, packet := range packets { | ||
commitmentPath := host.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, packet.Sequence) | ||
commitmentKey := crypto.Keccak256([]byte(commitmentPath)) | ||
var fixedArray [32]byte | ||
copy(fixedArray[:], commitmentKey) // Copy the slice into the fixed array | ||
|
||
res, err := chain.ibcHandler.GetCommitment( | ||
chain.callOptsFromQueryContext(ctx), | ||
fixedArray, | ||
) | ||
|
||
if err != nil { | ||
return packets, err | ||
} | ||
|
||
if res == [32]byte{0} { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
continue | ||
} | ||
|
||
activePackets = append(activePackets, packet) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove trailing blank lines from both functions and blocks. |
||
} | ||
|
||
return activePackets, nil | ||
|
||
} | ||
|
||
func (chain *Chain) findSentPackets(ctx core.QueryContext, fromHeight uint64) (core.PacketInfoList, error) { | ||
logger := chain.GetChannelLogger() | ||
now := time.Now() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,6 +356,24 @@ func (c *Chain) TxAcknowledgement(opts *bind.TransactOpts, msg *chantypes.MsgAck | |
}) | ||
} | ||
|
||
func (c *Chain) TxMsgTimeout(opts *bind.TransactOpts, msg *chantypes.MsgTimeout) (*gethtypes.Transaction, error) { | ||
return c.ibcHandler.TimeoutPacket(opts, ibchandler.IIBCChannelPacketTimeoutMsgTimeoutPacket{ | ||
Packet: ibchandler.Packet{ | ||
Sequence: msg.Packet.Sequence, | ||
SourcePort: msg.Packet.SourcePort, | ||
SourceChannel: msg.Packet.SourceChannel, | ||
DestinationPort: msg.Packet.DestinationPort, | ||
DestinationChannel: msg.Packet.DestinationChannel, | ||
Data: msg.Packet.Data, | ||
TimeoutHeight: ibchandler.HeightData(msg.Packet.TimeoutHeight), | ||
TimeoutTimestamp: msg.Packet.TimeoutTimestamp, | ||
}, | ||
Comment on lines
+361
to
+370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please define and use |
||
Proof: msg.ProofUnreceived, | ||
ProofHeight: pbToHandlerHeight(msg.ProofHeight), | ||
NextSequenceRecv: msg.NextSequenceRecv, | ||
}) | ||
} | ||
|
||
func (c *Chain) TxChannelUpgradeInit(opts *bind.TransactOpts, msg *chantypes.MsgChannelUpgradeInit) (*gethtypes.Transaction, error) { | ||
return c.ibcHandler.ChannelUpgradeInit(opts, ibchandler.IIBCChannelUpgradeBaseMsgChannelUpgradeInit{ | ||
PortId: c.pathEnd.PortID, | ||
|
@@ -468,6 +486,8 @@ func (c *Chain) BuildMessageTx(opts *bind.TransactOpts, msg sdk.Msg, skipUpdateC | |
tx, err = c.TxRecvPacket(opts, msg) | ||
case *chantypes.MsgAcknowledgement: | ||
tx, err = c.TxAcknowledgement(opts, msg) | ||
case *chantypes.MsgTimeout: | ||
tx, err = c.TxMsgTimeout(opts, msg) | ||
case *chantypes.MsgChannelUpgradeInit: | ||
tx, err = c.TxChannelUpgradeInit(opts, msg) | ||
case *chantypes.MsgChannelUpgradeTry: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can directly obtain an array value by using
crypto.Keccak256Hash
.Also, you can use
host.PacketCommitmentKey
to remove a type casting.