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(submitter): remove dumpPrivKey #15

Merged
merged 14 commits into from
Aug 20, 2024
8 changes: 8 additions & 0 deletions btcclient/client_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,11 @@ func (c *Client) GetHighUTXOAndSum() (*btcjson.ListUnspentResult, float64, error
func CalculateTxFee(feeRateAmount btcutil.Amount, size uint64) (uint64, error) {
return uint64(feeRateAmount.MulF64(float64(size) / 1024)), nil
}

func (c *Client) FundRawTransaction(tx *wire.MsgTx, opts btcjson.FundRawTransactionOpts, isWitness *bool) (*btcjson.FundRawTransactionResult, error) {
return c.Client.FundRawTransaction(tx, opts, isWitness)
}

func (c *Client) SignRawTransactionWithWallet(tx *wire.MsgTx) (*wire.MsgTx, bool, error) {
return c.Client.SignRawTransactionWithWallet(tx)
}
2 changes: 2 additions & 0 deletions btcclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ type BTCWallet interface {
WalletPassphrase(passphrase string, timeoutSecs int64) error
DumpPrivKey(address btcutil.Address) (*btcutil.WIF, error)
GetHighUTXOAndSum() (*btcjson.ListUnspentResult, float64, error)
FundRawTransaction(tx *wire.MsgTx, opts btcjson.FundRawTransactionOpts, isWitness *bool) (*btcjson.FundRawTransactionResult, error)
SignRawTransactionWithWallet(tx *wire.MsgTx) (*wire.MsgTx, bool, error)
}
15 changes: 11 additions & 4 deletions e2etest/bitcoind_node_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (h *BitcoindTestHandler) Start() {
}, startTimeout, 500*time.Millisecond, "bitcoind did not start")
}

// GetBlockCount retrieves the current number of blocks in the blockchain from the Bitcoind.
func (h *BitcoindTestHandler) GetBlockCount() (int, error) {
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"getblockcount"})
if err != nil {
Expand All @@ -78,6 +79,7 @@ func (h *BitcoindTestHandler) GetBlockCount() (int, error) {
return strconv.Atoi(parsedBuffStr)
}

// GenerateBlocks mines a specified number of blocks in the Bitcoind.
func (h *BitcoindTestHandler) GenerateBlocks(count int) *GenerateBlockResponse {
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"-generate", fmt.Sprintf("%d", count)})
require.NoError(h.t, err)
Expand All @@ -89,11 +91,10 @@ func (h *BitcoindTestHandler) GenerateBlocks(count int) *GenerateBlockResponse {
return &response
}

// CreateWallet creates a new wallet with the specified name and passphrase in the Bitcoind
func (h *BitcoindTestHandler) CreateWallet(walletName string, passphrase string) *CreateWalletResponse {
// last false on the list will create legacy wallet. This is needed, as currently
// we are signing all taproot transactions by dumping the private key and signing it
// on app level. Descriptor wallets do not allow dumping private keys.
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"createwallet", walletName, "false", "false", passphrase, "false", "false"})
// last arg is true which indicates we are using descriptor wallets they do not allow dumping private keys.
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"createwallet", walletName, "false", "false", passphrase, "false", "true"})
Copy link
Member Author

Choose a reason for hiding this comment

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

Legacy wallets were "false", true for descriptor wallets

require.NoError(h.t, err)

var response CreateWalletResponse
Expand All @@ -108,3 +109,9 @@ func (h *BitcoindTestHandler) InvalidateBlock(blockHash string) {
_, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"invalidateblock", blockHash})
require.NoError(h.t, err)
}

// ImportDescriptors imports a given Bitcoin address descriptor into the Bitcoind
func (h *BitcoindTestHandler) ImportDescriptors(descriptor string) {
_, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"importdescriptors", descriptor})
require.NoError(h.t, err)
}
2 changes: 1 addition & 1 deletion e2etest/container/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ImageConfig struct {
//nolint:deadcode
const (
dockerBitcoindRepository = "lncm/bitcoind"
dockerBitcoindVersionTag = "v24.0.1"
dockerBitcoindVersionTag = "v27.0"
)

// NewImageConfig returns ImageConfig needed for running e2e test.
Expand Down
1 change: 1 addition & 0 deletions e2etest/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (m *Manager) RunBitcoindResource(
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-zmqpubsequence=tcp://0.0.0.0:28333",
"-fallbackfee=0.0002",
},
},
noRestart,
Expand Down
51 changes: 43 additions & 8 deletions e2etest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"go.uber.org/zap"
"testing"
"time"
Expand Down Expand Up @@ -87,7 +89,6 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
btcHandler.Start()
passphrase := "pass"
_ = btcHandler.CreateWallet("default", passphrase)
blocksResponse := btcHandler.GenerateBlocks(int(numMatureOutputsInWallet))

cfg := defaultVigilanteConfig()

Expand All @@ -102,6 +103,13 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
}, nil)
require.NoError(t, err)

err = testRpcClient.WalletPassphrase(passphrase, 600)
require.NoError(t, err)

walletPrivKey, err := importPrivateKey(btcHandler)
require.NoError(t, err)
blocksResponse := btcHandler.GenerateBlocks(int(numMatureOutputsInWallet))

btcClient := initBTCClientWithSubscriber(t, cfg)

var buff bytes.Buffer
Expand Down Expand Up @@ -136,20 +144,14 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32) *TestManager {
return true
}, eventuallyWaitTimeOut, eventuallyPollTime)

err = testRpcClient.WalletPassphrase(passphrase, 600)
require.NoError(t, err)

walletPrivKey, err := testRpcClient.DumpPrivKey(minerAddressDecoded)
require.NoError(t, err)

return &TestManager{
TestRpcClient: testRpcClient,
BabylonHandler: bh,
BabylonClient: babylonClient,
BitcoindHandler: btcHandler,
BTCClient: btcClient,
Config: cfg,
WalletPrivKey: walletPrivKey.PrivKey,
WalletPrivKey: walletPrivKey,
}
}

Expand Down Expand Up @@ -227,3 +229,36 @@ func (tm *TestManager) CatchUpBTCLightClient(t *testing.T) {
_, err = tm.InsertBTCHeadersToBabylon(headers)
require.NoError(t, err)
}

func importPrivateKey(btcHandler *BitcoindTestHandler) (*btcec.PrivateKey, error) {
privKey, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}

wif, err := btcutil.NewWIF(privKey, regtestParams, true)
if err != nil {
return nil, err
}

// "combo" allows us to import a key and handle multiple types of btc scripts with a single descriptor command.
descriptor := fmt.Sprintf("combo(%s)", wif.String())

// Create the JSON descriptor object.
descJSON, err := json.Marshal([]map[string]interface{}{
{
"desc": descriptor,
"active": true,
"timestamp": "now", // tells Bitcoind to start scanning from the current blockchain height
"label": "test key",
},
})

if err != nil {
return nil, err
}

btcHandler.ImportDescriptors(string(descJSON))

return privKey, nil
}
1 change: 0 additions & 1 deletion e2etest/test_manager_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func (tm *TestManager) CreateBTCDelegation(
require.NoError(t, err)
btccParams := btccParamsResp.Params
for i := 0; i < int(btccParams.BtcConfirmationDepth); i++ {
//tm.MineBlockWithTxs(t, tm.RetrieveTransactionFromMempool(t, []*chainhash.Hash{}))
tm.mineBlock(t)
}

Expand Down
Loading
Loading