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

switch to trunk based dev #30

Merged
merged 14 commits into from
Sep 3, 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
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'main'
- 'dev'
tags:
- '*'

Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing

Btc-staker repository follows the same contributing rules as
[Babylon node](https://github.com/babylonlabs-io/babylon/blob/main/CONTRIBUTING.md)
repository.
5 changes: 5 additions & 0 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release Process

Btc-staker repository follows the same release process rules as
[Babylon node](https://github.com/babylonlabs-io/babylon/blob/main/RELEASE_PROCESS.md)
repository.
49 changes: 35 additions & 14 deletions cmd/stakercli/transaction/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,26 @@ type StakingTxData struct {
FinalityProviderPublicKeyHex string `json:"finality_provider_public_key_hex"`
StakingAmount int64 `json:"staking_amount"`
StakingTimeBlocks int64 `json:"staking_time_blocks"`
// ParamsVersion is the version of the global parameters aginst which is valid
ParamsVersion int64 `json:"params_version"`
}

type ValidityInfo struct {
ParametersVersion uint64 `json:"parameters_version"`
IsValid bool `json:"is_valid"`
ErrMsg string `json:"err_msg,omitempty"`
StakingData *StakingTxData `json:"staking_data,omitempty"`
}

type CheckPhase1StakingTxResponse struct {
IsValid bool `json:"is_valid"`
// StakingData will only be populated if the transaction is valid
StakingData *StakingTxData `json:"staking_data"`
ValidityInfo []*ValidityInfo `json:"validity_info"`
}

func validateTxAgainstParams(
tx *wire.MsgTx,
globalParams *parser.ParsedGlobalParams,
net *chaincfg.Params) *CheckPhase1StakingTxResponse {

var info []*ValidityInfo

for i := len(globalParams.Versions) - 1; i >= 0; i-- {
params := globalParams.Versions[i]

Expand All @@ -108,32 +113,48 @@ func validateTxAgainstParams(
net,
)
if err != nil {
info = append(info, &ValidityInfo{
ParametersVersion: params.Version,
IsValid: false,
ErrMsg: fmt.Sprintf("error parsing tx: %s", err.Error()),
})
continue
}

if parsed.OpReturnData.StakingTime < params.MinStakingTime || parsed.OpReturnData.StakingTime > params.MaxStakingTime {
info = append(info, &ValidityInfo{
ParametersVersion: params.Version,
IsValid: false,
ErrMsg: fmt.Sprintf("staking time %d is out of bounds", parsed.OpReturnData.StakingTime),
})
continue
}

if btcutil.Amount(parsed.StakingOutput.Value) < params.MinStakingAmount || btcutil.Amount(parsed.StakingOutput.Value) > params.MaxStakingAmount {
info = append(info, &ValidityInfo{
ParametersVersion: params.Version,
IsValid: false,
ErrMsg: fmt.Sprintf("staking amount %d is out of bounds", parsed.StakingOutput.Value),
})
continue
}

// At this point we know staking transaction is valid against this version of global params
return &CheckPhase1StakingTxResponse{
IsValid: true,
info = append(info, &ValidityInfo{
ParametersVersion: params.Version,
IsValid: true,
StakingData: &StakingTxData{
StakerPublicKeyHex: hex.EncodeToString(parsed.OpReturnData.StakerPublicKey.Marshall()),
FinalityProviderPublicKeyHex: hex.EncodeToString(parsed.OpReturnData.FinalityProviderPublicKey.Marshall()),
StakerPublicKeyHex: hex.EncodeToString(schnorr.SerializePubKey(parsed.OpReturnData.StakerPublicKey.PubKey)),
FinalityProviderPublicKeyHex: hex.EncodeToString(schnorr.SerializePubKey(parsed.OpReturnData.FinalityProviderPublicKey.PubKey)),
StakingAmount: parsed.StakingOutput.Value,
StakingTimeBlocks: int64(parsed.OpReturnData.StakingTime),
ParamsVersion: int64(params.Version),
},
}
}})

// We found latest valid version, no need to check further
break
}

return &CheckPhase1StakingTxResponse{
IsValid: false,
ValidityInfo: info,
}
}

Expand Down
16 changes: 9 additions & 7 deletions cmd/stakercli/transaction/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,15 @@ func FuzzCheckPhase1Tx(f *testing.F) {
r, t, app, checkArgs,
)
require.NotNil(t, resCheck)
require.True(t, resCheck.IsValid)
require.NotNil(t, resCheck.StakingData)
require.Equal(t, globalParams.Versions[0].Version, uint64(resCheck.StakingData.ParamsVersion))
require.Equal(t, stakerParams.StakingAmount, btcutil.Amount(resCheck.StakingData.StakingAmount))
require.Equal(t, stakerParams.StakingTime, uint16(resCheck.StakingData.StakingTimeBlocks))
require.Equal(t, keyToSchnorrHex(stakerParams.StakerPk), resCheck.StakingData.StakerPublicKeyHex)
require.Equal(t, keyToSchnorrHex(stakerParams.FinalityProviderPk), resCheck.StakingData.FinalityProviderPublicKeyHex)
require.Len(t, resCheck.ValidityInfo, 1)

require.True(t, resCheck.ValidityInfo[0].IsValid)
require.NotNil(t, resCheck.ValidityInfo[0].StakingData)
require.Equal(t, globalParams.Versions[0].Version, resCheck.ValidityInfo[0].ParametersVersion)
require.Equal(t, stakerParams.StakingAmount, btcutil.Amount(resCheck.ValidityInfo[0].StakingData.StakingAmount))
require.Equal(t, stakerParams.StakingTime, uint16(resCheck.ValidityInfo[0].StakingData.StakingTimeBlocks))
require.Equal(t, keyToSchnorrHex(stakerParams.StakerPk), resCheck.ValidityInfo[0].StakingData.StakerPublicKeyHex)
require.Equal(t, keyToSchnorrHex(stakerParams.FinalityProviderPk), resCheck.ValidityInfo[0].StakingData.FinalityProviderPublicKeyHex)
})
}

Expand Down
2 changes: 1 addition & 1 deletion itest/bitcoind_node_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (h *BitcoindTestHandler) CreateWallet(walletName string, passphrase string)
// 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"})
buff, _, err := h.m.ExecBitcoindCliCmd(h.t, []string{"createwallet", walletName, "false", "false", passphrase})
require.NoError(h.t, err)

var response CreateWalletResponse
Expand Down
2 changes: 1 addition & 1 deletion itest/containers/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 = "v26.0"
)

// NewImageConfig returns ImageConfig needed for running e2e test.
Expand Down
Loading
Loading