Skip to content
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: implement bitcoin relayer #432

Open
wants to merge 135 commits into
base: main
Choose a base branch
from

Conversation

shallcdn
Copy link

Description:

  • Implement Bitcoin relayer

Features:

  • Deposit BTC/Runes from BTC to Icon
  • Withdraw BTC/Runes from Icon to BTC
  • Rollback BTC/Runes when deposit fail
  • Refund BTC if the bridge message amount does not match the output to the relayer

Docs:

Including testing results and how to use bitcoin relayer

Mainnet contracts:

Name Address Token Id
XCall cxa07f426062a1384bdd762afa6a87d123fbc81c75
Asset manager cx2b763789b35d9a22db9b1ca41e2d9cc164283602  
Bitcoin address (dec 8) cx93e0ab1a31a16c98569ef1daff1dda13da187f7c 0x1.btc/0:0
UNCOMMON•GOODS (dec 0) cxd13eb06bfa756c3ca5a5aca7b7fe2d5ea01fc867 0x1.btc/1:0
Governance cx360034481214dedc3de0226f3bf2562bc0a371d5  
Xcall manager cxb86d8386f9847204dcf19d285cc3d4bbb686bdca  
Bitcoin multisig relayer 0x1.btc/bc1p2sdwgq7j32j250w8h47fe9v3hyc8fl2rdftwhxp0r7ww89mcwrns5reskh  

Checklist:

Please review the CONTRIBUTING.md file for detailed contributing guidelines.

zuttodoS and others added 30 commits June 25, 2024 16:34
…wallet (#2)

* feat: add transmission and bitcoin module

---------

Co-authored-by: k0r1 <[email protected]>
Add Bitcoin taproot multisig wallet library
…wallet (#2)

* feat: add transmission and bitcoin module

---------

Co-authored-by: k0r1 <[email protected]>
.gitignore Outdated Show resolved Hide resolved
.vscode/launch.json Outdated Show resolved Hide resolved
utils/multisig/tx.go Outdated Show resolved Hide resolved

for {
select {
case <-pollHeightTicker.C:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add sleep or avoid using default so that the cpus usage would not be 100% within the loop.


heightStream := p.getHeightStream(done, fromHeight, toHeight)

diff := int(toHeight-fromHeight) / 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar implementation on other chains have been reverted to use simpler single threaded executions to avoid hitting rate limit in RPCs when numerous blocks are missing. So, it would be better to refactor this as well

@@ -0,0 +1,1437 @@
package bitcoin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider refactoring this file to multiple files(listener,routes,tx and so on) to avoid creating too large file.

}

func (p *Provider) FetchTxMessages(ctx context.Context, txHash string) ([]*relayTypes.Message, error) {
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add implementation here to fetch transaction based on any given txHash if possible as it would make manual replaying transaction much simpler and effective based on tx hash.

p.logger.Info("Message stored in LevelDB", zap.String("key", string(key)), zap.Any("message", message))

if p.cfg.Mode != MasterMode {
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call the callback for cleaning the message status since this won't process this,

for _, block := range blockInfo {
messages = append(messages, block.Messages...)
}
blockInfoChan <- &relayTypes.BlockInfo{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this make sense only for the master mode to push to the channel since the icon chain will route the message pushed here ?


for i := param.StartHeight; i <= param.EndHeight; i++ {

blockHash, err := c.client.GetBlockHash(int64(i))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify polling by just getting the address history txn of relayer address and then fetching the transaction directly or this approach just won;t work ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants