Skip to content

Commit

Permalink
Merge branch 'main' into pre-approval-flow-test
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Oct 7, 2024
2 parents 45896b9 + b128f1d commit efc4cd1
Show file tree
Hide file tree
Showing 61 changed files with 203 additions and 160 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ transaction fee refunding mechanism for covenant signatures and finality signatu
refund transaction fee for certain transactions from protocol stakeholders
* [#137](https://github.com/babylonlabs-io/babylon/pull/137) Sdapt tests to the
pre-approval flow.
* [#138](https://github.com/babylonlabs-io/babylon/pull/138) Intercept staking module
messages inside `authz.MsgExec`.

### Misc Improvements

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ lint-go:

.PHONY: lint lint-fix

format: ## Run code formater
format: ## Run code formatter
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -name '*.pb.go' | xargs goimports -w -local github.com/babylonlabs-io/babylon
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This upgrade loads 5 JSONs from strings in different files.

This upgrade accepts insertion of multiple
[`btclighttypes.BTCHeaderInfo`](../../../x/btclightclient/types/btclightclient.pb.go#36)
due to Babylon Phase-1 and Phase-2 launch will be a few months appart, so
due to Babylon Phase-1 and Phase-2 launch will be a few months apart, so
during Phase-1 Babylon accepts BTC delegations without Babylonchain running.
At the time of launching the Babylonchain it is needed all the BTC block
headers that has passed since babylon started to accept BTC staking messages,
Expand Down
6 changes: 3 additions & 3 deletions btcstaking/identifiable_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

const (
// length of tag prefix indentifying staking transactions
// TagLen length of tag prefix identifying staking transactions
TagLen = 4
// 4 bytes tag + 1 byte version + 32 bytes staker public key + 32 bytes finality provider public key + 2 bytes staking time
// V0OpReturnDataSize 4 bytes tag + 1 byte version + 32 bytes staker public key + 32 bytes finality provider public key + 2 bytes staking time
V0OpReturnDataSize = 71

v0OpReturnCreationErrMsg = "cannot create V0 op_return data"
Expand Down Expand Up @@ -391,7 +391,7 @@ func ParseV0StakingTx(
}

if opReturnData.Version != 0 {
return nil, fmt.Errorf("unexpcted version: %d, expected: %d", opReturnData.Version, 0)
return nil, fmt.Errorf("unexpected version: %d, expected: %d", opReturnData.Version, 0)
}

// 3. Op return seems to be valid V0 op return output. Now, we need to check whether
Expand Down
8 changes: 4 additions & 4 deletions btcstaking/identifiable_staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ func FuzzGenerateAndParseValidV0StakingTransaction(f *testing.F) {
r := rand.New(rand.NewSource(seed))
// 3 - 10 covenants
numCovenantKeys := uint32(r.Int31n(7) + 3)
quroum := uint32(r.Intn(int(numCovenantKeys)) + 1)
quorum := uint32(r.Intn(int(numCovenantKeys)) + 1)
stakingAmount := btcutil.Amount(r.Int63n(1000000000) + 10000)
stakingTime := uint16(r.Int31n(math.MaxUint16-1) + 1)
tag := datagen.GenRandomByteArray(r, btcstaking.TagLen)
net := &chaincfg.MainNetParams

sc := GenerateTestScenario(r, t, 1, numCovenantKeys, quroum, stakingAmount, stakingTime)
sc := GenerateTestScenario(r, t, 1, numCovenantKeys, quorum, stakingAmount, stakingTime)

outputs, err := btcstaking.BuildV0IdentifiableStakingOutputs(
tag,
sc.StakerKey.PubKey(),
sc.FinalityProviderKeys[0].PubKey(),
sc.CovenantPublicKeys(),
quroum,
quorum,
stakingTime,
stakingAmount,
net,
Expand All @@ -77,7 +77,7 @@ func FuzzGenerateAndParseValidV0StakingTransaction(f *testing.F) {
tx,
tag,
sc.CovenantPublicKeys(),
quroum,
quorum,
net,
)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion btcstaking/scripts_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// private helper to assemble multisig script
// if `withVerify` is ture script will end with OP_NUMEQUALVERIFY otherwise with OP_NUMEQUAL
// if `withVerify` is true script will end with OP_NUMEQUALVERIFY otherwise with OP_NUMEQUAL
// SCRIPT: <Pk1> OP_CHEKCSIG <Pk2> OP_CHECKSIGADD <Pk3> OP_CHECKSIGADD ... <PkN> OP_CHECKSIGADD <threshold> OP_NUMEQUALVERIFY (or OP_NUMEQUAL)
func assembleMultiSigScript(
pubkeys []*btcec.PublicKey,
Expand Down
12 changes: 6 additions & 6 deletions btcstaking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func buildSlashingTxFromOutpoint(
// Create a new btc transaction
tx := wire.NewMsgTx(wire.TxVersion)
// TODO: this builds input with sequence number equal to MaxTxInSequenceNum, which
// means this tx is not replacable.
// means this tx is not replaceable.
input := wire.NewTxIn(&stakingOutput, nil, nil)
tx.AddTxIn(input)
tx.AddTxOut(wire.NewTxOut(int64(slashingAmount), slashingPkScript))
Expand Down Expand Up @@ -157,7 +157,7 @@ func BuildSlashingTxFromStakingTxStrict(
stakingTxHash := stakingTx.TxHash()
stakingOutpoint := wire.NewOutPoint(&stakingTxHash, stakingOutputIdx)

// Create taproot address commiting to timelock script
// Create taproot address committing to timelock script
si, err := BuildRelativeTimelockTaprootScript(
stakerPk,
slashChangeLockTime,
Expand Down Expand Up @@ -198,15 +198,15 @@ func IsTransferTx(tx *wire.MsgTx) error {
// IsSimpleTransfer Simple transfer transaction is a transaction which:
// - has exactly one input
// - has exactly one output
// - is not replacable
// - is not replaceable
// - does not have any locktime
func IsSimpleTransfer(tx *wire.MsgTx) error {
if err := IsTransferTx(tx); err != nil {
return fmt.Errorf("invalid simple tansfer tx: %w", err)
return fmt.Errorf("invalid simple transfer tx: %w", err)
}

if tx.TxIn[0].Sequence != wire.MaxTxInSequenceNum {
return fmt.Errorf("simple transfer tx must not be replacable")
return fmt.Errorf("simple transfer tx must not be replaceable")
}

if tx.LockTime != 0 {
Expand Down Expand Up @@ -329,7 +329,7 @@ func validateSlashingTx(
// - funding transaction has output committing to the provided script
// - slashing transaction is valid
// - slashing transaction input hash is pointing to funding transaction hash
// - slashing transaction input index is pointing to funding transaction output commiting to the script
// - slashing transaction input index is pointing to funding transaction output committing to the script
func CheckTransactions(
slashingTx *wire.MsgTx,
fundingTransaction *wire.MsgTx,
Expand Down
8 changes: 4 additions & 4 deletions btcstaking/testvectors/vectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
},
{
"name": "1 finality key, 3/5 covenant committe, 1 staker key with op_return",
"name": "1 finality key, 3/5 covenant committee, 1 staker key with op_return",
"parameters": {
"covenant_public_keys": [
"02cc5c77da065c490a320834fdcf2c3da70ecd442054c90f874a1edb4669607b83",
Expand Down Expand Up @@ -71,7 +71,7 @@
}
},
{
"name": "3 finality keys, 3/5 covenant committe, 1 staker key with no op_return",
"name": "3 finality keys, 3/5 covenant committee, 1 staker key with no op_return",
"parameters": {
"covenant_public_keys": [
"02042916c9cd52cfa146118c37b6b118f082bb50fb91da1c51b76dfc2100e66f00",
Expand Down Expand Up @@ -110,7 +110,7 @@
}
},
{
"name": "1 finality keys, 7/9 covenant committe, 1 staker key with op_return",
"name": "1 finality keys, 7/9 covenant committee, 1 staker key with op_return",
"parameters": {
"covenant_public_keys": [
"0287ed5bb2d036baf209eb49520327f6bd05285dabd30c97f239c3a69ff419950b",
Expand Down Expand Up @@ -151,7 +151,7 @@
}
},
{
"name": "10 finality keys, 18/20 covenant committe, 1 staker key with no op_return",
"name": "10 finality keys, 18/20 covenant committee, 1 staker key with no op_return",
"parameters": {
"covenant_public_keys": [
"02e3803a6ecff76daf35709c8484f382783d211970f22397d7a258f40ca3b46304",
Expand Down
8 changes: 4 additions & 4 deletions client/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Client) SendMsgsToMempool(ctx context.Context, msgs []sdk.Msg) error {
}
return sendMsgErr
}, retry.Context(ctx), rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
c.logger.Debug("retrying", zap.Uint("attemp", n+1), zap.Uint("max_attempts", rtyAttNum), zap.Error(err))
c.logger.Debug("retrying", zap.Uint("attempt", n+1), zap.Uint("max_attempts", rtyAttNum), zap.Error(err))
})); err != nil {
return err
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func (c *Client) ReliablySendMsgs(ctx context.Context, msgs []sdk.Msg, expectedE
}
return nil
}, retry.Context(ctx), rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
c.logger.Debug("retrying", zap.Uint("attemp", n+1), zap.Uint("max_attempts", rtyAttNum), zap.Error(err))
c.logger.Debug("retrying", zap.Uint("attempt", n+1), zap.Uint("max_attempts", rtyAttNum), zap.Error(err))
})); err != nil {
return nil, err
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (c *Client) ReliablySendMsgsWithSigner(ctx context.Context, signerAddr sdk.
wg.Done()
return nil
}, retry.Context(ctx), rtyAtt, rtyDel, rtyErr, retry.OnRetry(func(n uint, err error) {
c.logger.Debug("retrying", zap.Uint("attemp", n+1), zap.Uint("max_attempts", rtyAttNum), zap.Error(err))
c.logger.Debug("retrying", zap.Uint("attempt", n+1), zap.Uint("max_attempts", rtyAttNum), zap.Error(err))
})); err != nil {
return nil, err
}
Expand Down Expand Up @@ -377,7 +377,7 @@ func (c *Client) CalculateGas(ctx context.Context, txf tx.Factory, signingPK cry
// Sign signs a given tx with the private key. The bytes signed over are canconical.
// The resulting signature will be added to the transaction builder overwriting the previous
// ones if overwrite=true (otherwise, the signature will be appended).
// Signing a transaction with mutltiple signers in the DIRECT mode is not supprted and will
// Signing a transaction with mutltiple signers in the DIRECT mode is not supported and will
// return an error.
// An error is returned upon failure.
func Sign(
Expand Down
2 changes: 1 addition & 1 deletion client/docs/diagrams/submit_checkpoint.puml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ loop
Bitcoin --> submitter : Wait for previous checkpoint carrier BTC block to embed
note right
Even a light client can do this,
becuase the BTC block to observe
because the BTC block to observe
is part of the Event from Babylon.

Waiting ensures the checkpoint
Expand Down
Loading

0 comments on commit efc4cd1

Please sign in to comment.