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

chore(*): wrap staker errs #29

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
environment:
- SNAPSHOT_FILE=babylon.tar.gz
- RPC_URL=https://rpc.devnet.babylonlabs.io
- GENESIS_PATH=""
- GENESIS_PATH=
volumes:
- ./scripts/init_master.sh:/scripts/init_master.sh
- ./snapshots:/snapshots
Expand Down Expand Up @@ -50,10 +50,11 @@ services:
"
environment:
- RPC_URL=https://rpc.devnet.babylonlabs.io
- GENESIS_PATH=""
- GENESIS_PATH=
volumes:
- ./scripts/init_follower.sh:/scripts/init_follower.sh
- ./babylond_data_follower:/root/.babylond
- ./snapshots:/snapshots # convenient to put genesis.json here
ports:
- "26658:26656" # Tendermint RPC for follower
- "26667:26657" # Tendermint P2P for follower
Expand Down
40 changes: 19 additions & 21 deletions harness/btcstaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func (s *BTCStaker) requestFunding(ctx context.Context) bool {
return false
}

// Wait for funding response or timeout
waitCtx, cancel := context.WithTimeout(ctx, 1*time.Minute)
// Wait for funding response or timeout.
// Long time out needed, once we hit over 200k delegations, this takes more than a minute
waitCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()

select {
Expand Down Expand Up @@ -397,7 +398,7 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
unbondingTime := uint16(100)
covKeys, err := bbnPksToBtcPks(params.CovenantPks)
if err != nil {
return err
return fmt.Errorf("err bbnPksToBtcPks: %w", err)
}

stakingInfo, err := staking.BuildStakingInfo(
Expand All @@ -410,14 +411,13 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
regtestParams,
)
if err != nil {
return err
return fmt.Errorf("err BuildStakingInfo: %w", err)
}

stakingTx, hash, err := s.tm.AtomicFundSignSendStakingTx(stakingInfo.StakingOutput)
if err != nil {
return err
return fmt.Errorf("err AtomicFundSignSendStakingTx: %w", err)
}
//fmt.Printf("send staking tx with hash %s \n", hash)

// TODO: hardcoded two in tests
inclusionProof := s.waitForTransactionConfirmation(ctx, hash, 2)
Expand All @@ -427,13 +427,11 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
return fmt.Errorf("empty inclusion proof")
}

//fmt.Printf("staking tx confirmed with hash %s \n", hash)

unbondingTxValue := params.MinStakingValueSat - params.UnbondingFeeSat

serializedStakingTx, err := bbntypes.SerializeBTCTx(stakingTx)
if err != nil {
return err
return fmt.Errorf("err staking SerializeBTCTx %w", err)
}

unbondingTx := wire.NewMsgTx(2)
Expand All @@ -454,13 +452,13 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
)

if err != nil {
return err
return fmt.Errorf("err BuildUnbondingInfo: %w", err)
}
unbondingTx.AddTxOut(unbondingInfo.UnbondingOutput)

serializedUnbondingTx, err := bbntypes.SerializeBTCTx(unbondingTx)
if err != nil {
return err
return fmt.Errorf("err unbonding SerializeBTCTx %w", err)
}

// build slashing for staking and unbondidn
Expand All @@ -475,12 +473,12 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
regtestParams,
)
if err != nil {
return err
return fmt.Errorf("err BuildSlashingTxFromStakingTxStrict %w", err)
}

stakingSlashingPath, err := stakingInfo.SlashingPathSpendInfo()
if err != nil {
return err
return fmt.Errorf("err SlashingPathSpendInfo %w", err)
}

unbondingSlashing, err := staking.BuildSlashingTxFromStakingTxStrict(
Expand All @@ -494,11 +492,11 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
regtestParams,
)
if err != nil {
return err
return fmt.Errorf("err BuildSlashingTxFromStakingTxStrict %w", err)
}
unbondingSlashingPath, err := unbondingInfo.SlashingPathSpendInfo()
if err != nil {
return err
return fmt.Errorf("err SlashingPathSpendInfo %w", err)
}

signStakingSlashingRes, err := s.SignOneInputTaprootSpendingTransaction(stakerPk, &TaprootSigningRequest{
Expand All @@ -510,7 +508,7 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
},
})
if err != nil {
return err
return fmt.Errorf("err SignOneInputTaprootSpendingTransaction %w", err)
}

signUnbondingSlashingRes, err := s.SignOneInputTaprootSpendingTransaction(stakerPk, &TaprootSigningRequest{
Expand All @@ -522,23 +520,23 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
},
})
if err != nil {
return err
return fmt.Errorf("err SignOneInputTaprootSpendingTransaction %w", err)
}

stakingSlashingTx, err := bbntypes.SerializeBTCTx(stakingSlashing)
if err != nil {
return err
return fmt.Errorf("err staking SerializeBTCTx %w", err)
}
stakingSlashingSig := bbntypes.NewBIP340SignatureFromBTCSig(signStakingSlashingRes.Signature)
unbondingSlashingTx, err := bbntypes.SerializeBTCTx(unbondingSlashing)
if err != nil {
return err
return fmt.Errorf("err unbonding SerializeBTCTx %w", err)
}
unbondingSlashingSig := bbntypes.NewBIP340SignatureFromBTCSig(signUnbondingSlashingRes.Signature)

pop, err := s.signBip322NativeSegwit(stakerAddress)
if err != nil {
return err
return fmt.Errorf("err signBip322NativeSegwit %w", err)
}

msgBTCDel := &bstypes.MsgCreateBTCDelegation{
Expand All @@ -563,7 +561,7 @@ func (s *BTCStaker) buildAndSendStakingTransaction(
start := time.Now()
resp, err := s.client.SendMsgs(ctx, []sdk.Msg{msgBTCDel})
if err != nil {
return err
return fmt.Errorf("err sending MsgCreateBTCDelegation %w", err)
}
if resp == nil {
return fmt.Errorf("resp from send msg is nil %v", msgBTCDel)
Expand Down
1 change: 0 additions & 1 deletion harness/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ func (tm *TestManager) AtomicFundSignSendStakingTx(stakingOutput *wire.TxOut) (*
tx := wire.NewMsgTx(2)
tx.AddTxOut(stakingOutput)

// todo(lazar): investigate if we can push this more, currently max ~50txs/block
lock := true
rawTxResult, err := tm.TestRpcClient.FundRawTransaction(tx, btcjson.FundRawTransactionOpts{
FeeRate: &feeRate,
Expand Down