Help understanding how the relayer gets new messages on receiver.go #809
-
Hi guys, I've been trying to follow the I know that when the BMC has a new msg to send to the relayer, it will emit this event. I thought the relayer should be lsitening to this event at all times, but it is currently only doing so, in a way that doesn't make sense to me. So from what I understood, when the relayer detects that the heigh on the BSC blockchain increased, it will try to scan the latest block added there and obtain its receipts. After getting the receipts of the latest bsc block, the relayer will aim to use them to try to generate the RelayReceipts. During that process ,it will wait for the above mentioned BMC event to be triggered, by calling this method. However, what is totally unclear to me here, is what's the role of the first Receipts here, being that they are being used as inputs to get the information sent from the bmc emitted event, but I don't understand what's going on. By inspecting, it leads to some JSON encoding that I am not being able to follow. So to sum up, I am mainly looking for answers to these 2 questions:
Thank you and sorry for the long text! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
When a user interacts with BTP Token Service smart contract deployed on a chain (e.g a user invokes transfer method of BTS contract on icon chain), an event log of type Message is generated by BMC contract and stored on that chain. Following is the example of such transaction done on ICON contract: This Message event has the actual BTP Message that needs to be passed to the other chain. To do this:
This procedure is the same for BSC chain's receiver as well. It will scan blocks generated on BSC chain and look for Message event type generated by BMC Periphery Contract. The bmcperiphery_gen.go is an auto-generated interface that makes it easier to work with type Message event. In conclusion, BTP Message is present in transaction events, which the relayer needs to find (by scanning blocks) and forward it to target chain. |
Beta Was this translation helpful? Give feedback.
-
First of all thanks for the quick and detailed answer! I still have some doubts though, here is how I currently see the icon bridge messaging flow :
Please help me figure out what I am thinking wrong because, according to this logic:
|
Beta Was this translation helpful? Give feedback.
-
This message is received, processed and another Message event is generated by ChainB. This acknowledgement Message is picked up and forwarded by relayer running in the opposite direction (chainB-> chainA). Finally the chainA receives the acknowledgement and unlocks the locked fund. So, for successful transfer there are a pair of Message Events generated. The number of such Message event exchanges depends upon how a Service Handler (e.g. BTS) operates.
Logic for handling successful or failed token transfers is entirely up to the Service Handler (Token Service smart contract) to decide and implement Service Handler only needs to work with BMC contract to generate a Message event if it needs to communicate with other chain. |
Beta Was this translation helpful? Give feedback.
-
Also on docs: https://github.com/icon-project/icon-bridge/blob/main/docs/token-transfer-flow.md |
Beta Was this translation helpful? Give feedback.
-
Awesome explanation, thank you so much |
Beta Was this translation helpful? Give feedback.
This message is received, processed and another Message event is generated by ChainB. This acknowledgement Message is picked up and forwarded by relayer running in the opposite direction (chainB-> chainA). Finally the chainA receives the acknowledgement and unlocks the locked fund. So, for successful transfer there are a pair of Me…