Skip to content

Commit

Permalink
Fix: do not send signed staking transaction to btc
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Oct 15, 2024
1 parent 1362858 commit 82e0aba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions staker/stakerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,23 @@ func (app *StakerApp) handlePreApprovalCmd(cmd *stakingRequestCmd) error {
func (app *StakerApp) handlePostApprovalCmd(cmd *stakingRequestCmd) error {

Check failure on line 1316 in staker/stakerapp.go

View workflow job for this annotation

GitHub Actions / lint_test / integration-tests

undefined: stakingRequestCmd

Check failure on line 1316 in staker/stakerapp.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

undefined: stakingRequestCmd

Check failure on line 1316 in staker/stakerapp.go

View workflow job for this annotation

GitHub Actions / lint_test / unit-tests

undefined: stakingRequestCmd
bestBlockHeight := app.currentBestBlockHeight.Load()

_, err := app.wc.SendRawTransaction(cmd.stakingTx, true)
err := app.wc.UnlockWallet(defaultWalletUnlockTimeout)

if err != nil {
return err
}

tx, fullySignd, err := app.wc.SignRawTransaction(cmd.stakingTx)

if err != nil {
return err
}

if !fullySignd {
return fmt.Errorf("failed to fully sign transaction with hash %s", cmd.stakingTxHash)
}

_, err = app.wc.SendRawTransaction(tx, true)

if err != nil {
return err
Expand Down Expand Up @@ -1780,8 +1796,9 @@ func (app *StakerApp) StakeFunds(

feeRate := app.feeEstimator.EstimateFeePerKb()

// Create unsigned transaction by wallet
tx, err := app.wc.CreateAndSignTx([]*wire.TxOut{stakingInfo.StakingOutput}, btcutil.Amount(feeRate), stakerAddress)
// Create unsigned transaction by wallet without signing. Signing will happen
// in next steps
tx, err := app.wc.CreateTransaction([]*wire.TxOut{stakingInfo.StakingOutput}, btcutil.Amount(feeRate), stakerAddress)

if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion stakerdb/trackedtransactionstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestStateTransitions(t *testing.T) {
// Inital state
storedTx, err := s.GetTransaction(&txHash)
require.NoError(t, err)
require.Equal(t, proto.TransactionState_TRANSACTION_CREATED, storedTx.State)
require.Equal(t, proto.TransactionState_SENT_TO_BTC, storedTx.State)
require.Equal(t, uint64(1), storedTx.StoredTransactionIdx)
// Confirmed
hash := datagen.GenRandomBtcdHash(r)
Expand Down
2 changes: 1 addition & 1 deletion walletcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type WalletController interface {
SignRawTransaction(tx *wire.MsgTx) (*wire.MsgTx, bool, error)
// requires wallet to be unlocked
CreateAndSignTx(
output []*wire.TxOut,
outputs []*wire.TxOut,
feeRatePerKb btcutil.Amount,
changeAddress btcutil.Address,
) (*wire.MsgTx, error)
Expand Down

0 comments on commit 82e0aba

Please sign in to comment.