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

rebase to latest main #34

Merged
merged 29 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f22ee2f
Merge pull request #107 from babylonchain/release/v0.1.0
KonradStaniec Feb 8, 2024
515865b
Merge pull request #154 from babylonchain/release/v0.2.0
KonradStaniec May 15, 2024
9250416
Merge pull request #180 from babylonchain/release/v0.3.0
KonradStaniec Jul 3, 2024
976c1a5
Merge pull request #183 from babylonchain/gai/release-v0.4.0
gitferry Jul 16, 2024
0961f94
Merge pull request #3 from babylonlabs-io/release/v0.5.0
KonradStaniec Jul 30, 2024
17fad51
Fix handling of the restart during unbonding (#20)
KonradStaniec Aug 9, 2024
2645e95
Sign taproot thorugh psbt (#21)
KonradStaniec Aug 12, 2024
881e10d
modify license
KonradStaniec Aug 16, 2024
06abcc3
Merge pull request #23 from babylonlabs-io/chore/modify-license
KonradStaniec Aug 16, 2024
4e6e9bc
Merge pull request #24 from babylonlabs-io/chore/modify-license
KonradStaniec Aug 16, 2024
4b80c69
chore: add wallet rpc name to the host connection config
RafilxTenfen Aug 16, 2024
02ca753
chore: add wallet name for testing
RafilxTenfen Aug 16, 2024
c6d6b37
chore: remove params and add check if wallet name is set to create fu…
RafilxTenfen Aug 16, 2024
e81317c
chore: unset wallet name to verify case if it has sinlge wallet and h…
RafilxTenfen Aug 16, 2024
ef58d6f
fix: there is more than one wallet created
RafilxTenfen Aug 16, 2024
8e3eece
chore: rename func to rpcHostURL
RafilxTenfen Aug 16, 2024
6734642
fix: add wallet name to TestBitcoindWalletRpcApi
RafilxTenfen Aug 16, 2024
1606ca1
Merge pull request #25 from babylonlabs-io/rafilx/add-btc-wallet-name
RafilxTenfen Aug 19, 2024
18b5b71
Impove check transaction command (#26)
KonradStaniec Aug 21, 2024
008569f
Add withdrawal command
KonradStaniec Aug 29, 2024
1fad96a
Merge pull request #27 from babylonlabs-io/feat/withdraw-command
KonradStaniec Aug 30, 2024
1a86048
Merge pull request #28 from babylonlabs-io/feat/withdraw-command
KonradStaniec Aug 30, 2024
e4c2ed2
switch to trunk based dev (#29)
KonradStaniec Sep 2, 2024
4530202
Merge pull request #30 from babylonlabs-io/dev
KonradStaniec Sep 3, 2024
dac0bb6
feat: parameters upgrade (#31)
KonradStaniec Sep 4, 2024
cef0e86
Bump babylon to latest stable version (#33)
KonradStaniec Sep 20, 2024
b18fb27
fix test/e2e
SebastianElvis Sep 25, 2024
0d1a83d
Merge branch 'main' into try-rebase
SebastianElvis Sep 25, 2024
59cb769
fix dockerfile
SebastianElvis Sep 25, 2024
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.
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
FROM golang:1.22.3 as builder

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Install cli tools for building and final image
RUN apt-get update && apt-get install -y make git bash gcc curl jq

RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN git config --global url."[email protected]:".insteadOf "https://github.com/"
ENV GOPRIVATE=github.com/babylonlabs-io/*

# Build
WORKDIR /go/src/github.com/babylonlabs-io/btc-staker
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/btc-staker/
RUN --mount=type=secret,id=sshKey,target=/root/.ssh/id_rsa go mod download
RUN go mod download

# Copy the rest of the files
COPY ./ /go/src/github.com/babylonlabs-io/btc-staker/
Expand Down Expand Up @@ -44,4 +40,4 @@

ENTRYPOINT ["/bin/stakerd"]
CMD []
STOPSIGNAL SIGTERM
STOPSIGNAL SIGTERM
78 changes: 74 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,82 @@ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.

Parameters

Licensor: Babylon Labs, Ltd.
Licensor: Babylon Labs Ltd.

Licensed Work: btc-staker
The Licensed Work is (c) 2023 Babylon Labs, Ltd.

Additional Use Grant: None.
The Licensed Work is (c) 2024 Babylon Labs Ltd.

Additional Use Grant:

In addition to the uses permitted under the non-production license below,
we grant you a limited, non-exclusive, non-transferable, non-sublicensable,
revocable license, limited as set forth below, to use the Licensed Work
in this repository for production commercial uses built on or using and integrated
with the Babylon Protocol, not including Competing Uses.

Any use beyond the scope of this license, including uses that are not built on or
using and integrated with the Babylon Protocol, or are Competing Uses,
will terminate this license to you, automatically and without notice.

This License applies separately and solely to the specific versions of the Licensed Work
in the specified repository on or before the date of this License, and we may require a
different license and different provisions for each subsequent version of the
Licensed Work released by us.

"Babylon Labs", "we", "our", or "us" means Babylon Labs Ltd.

"Babylon Protocol" means the Bitcoin staking protocol as further described in the documentation
here (https://docs.babylonlabs.io/docs/introduction/babylon-overview), as updated from time to time.

"Competing Use" means any use of the Licensed Work in any product, software, protocol, network,
application, or service that is made available to any party and that
(i) substitutes for the use of the Babylon Protocol,
(ii) offers the same or substantially similar functionality as the Babylon Protocol or
(iii) is built on or uses a protocol with substantially similar functionality as the Babylon Protocol
or otherwise facilitates the staking of bitcoin other than by utilizing the Babylon Protocol.

The provisions in this License apply to each individual, entity, group, or association
(each and collectively, "you" or "your") who uses the Licensed Work for production,
and you agree to such provisions. Your production use of the Licensed Work is conditional on your
agreement to this License. If you do not agree and consent to be bound to this License,
do not so use the Software.

If you do not fall within the limited scope of this license as described above or below,
or are otherwise not in strict compliance with this License, then this production license does not
extend to you and does not grant you any production use, including any copying, distributing, or
making any derivative use of the Licensed Work for production purposes.

Limited Scope of License. Your commercial production license to the Licensed Work
under this License does not extend to any use:

1. unless you have legal capacity to consent and agree to be bound by this License;
2. unless you have the technical knowledge necessary or advisable to understand and evaluate the
risks of using the Licensed Work and the Babylon Protocol;
3. if you are a resident or agent of, or an entity organized, incorporated or doing business in,
Afghanistan, Belarus, Bosnia and Herzegovina, Burundi, Central African Republic, Crimea, Cuba,
Democratic People's Republic of Korea, Democratic Republic of the Congo,
Donetsk or Luhansk Regions of Ukraine, Eritrea, Guinea, Guinea-Bissau, Haiti, Iran, Iraq, Lebanon,
Libya, Mali, Myanmar, Nicaragua, Russia, Somalia, South Sudan, Sudan, Syria, Venezuela, Yemen,
or Zimbabwe or any other country to which the United States, the United Kingdom,
the European Union or any of its member states or the United Nations or any of its member states
(collectively, the "Major Jurisdictions") embargoes goods or imposes sanctions
(such embargoed or sanctioned territories, collectively, the "Restricted Territories");
4. if you are, or if you directly or indirectly own or control, from any person or entity that is
listed on any sanctions list or equivalent maintained by any of the Major Jurisdictions
(collectively, "Sanctions Lists Persons");
5. to transact in or with any Restricted Territories or Sanctions List Persons;
6. if you are a U.S. Person as defined in 17 CFR § 230.902, or currently or ordinarily located or
resident in (or incorporated or organized in) the United States of America, Canada, or
Australia (collectively, "Excluded Jurisdictions"), or to transact in or with Excluded Jurisdictions;
7. to defraud, or otherwise materially mislead, any person;
8. in violation of applicable laws, rules or regulations in your relevant jurisdiction;
9. that circumvents any sanctions or export controls targeting you or the country or territory where
you are located; or
10. in any activity that transmits, exchanges, or is otherwise supported by the direct or indirect
proceeds of criminal or fraudulent activity.

Any production use of the Licensed Work by you confirms your agreement to the foregoing limitations,
and your understanding and agreement that they are limitations and not restrictions.

Change Date: 2027-01-20 (January 20th, 2027)

Expand Down
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.
54 changes: 42 additions & 12 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ func NewBabylonController(
}

type StakingTrackerResponse struct {
SlashingAddress btcutil.Address
SlashingPkScript []byte
SlashingRate sdkmath.LegacyDec
MinComissionRate sdkmath.LegacyDec
CovenantPks []*btcec.PublicKey
CovenantQuruomThreshold uint32
MinSlashingFee btcutil.Amount
MinUnbodningTime uint16
MinUnbondingTime uint16
UnbondingFee btcutil.Amount
MinStakingTime uint16
MaxStakingTime uint16
MinStakingValue btcutil.Amount
MaxStakingValue btcutil.Amount
}

type FinalityProviderInfo struct {
Expand Down Expand Up @@ -176,18 +181,23 @@ func (bc *BabylonController) Params() (*StakingParams, error) {

minUnbondingTime := sdkmath.Max[uint16](
uint16(bccParams.CheckpointFinalizationTimeout),
stakingTrackerParams.MinUnbodningTime,
stakingTrackerParams.MinUnbondingTime,
)

return &StakingParams{
ConfirmationTimeBlocks: uint32(bccParams.BtcConfirmationDepth),
FinalizationTimeoutBlocks: uint32(bccParams.CheckpointFinalizationTimeout),
SlashingAddress: stakingTrackerParams.SlashingAddress,
SlashingPkScript: stakingTrackerParams.SlashingPkScript,
CovenantPks: stakingTrackerParams.CovenantPks,
MinSlashingTxFeeSat: stakingTrackerParams.MinSlashingFee,
SlashingRate: stakingTrackerParams.SlashingRate,
CovenantQuruomThreshold: stakingTrackerParams.CovenantQuruomThreshold,
MinUnbondingTime: minUnbondingTime,
UnbondingFee: stakingTrackerParams.UnbondingFee,
MinStakingTime: stakingTrackerParams.MinStakingTime,
MaxStakingTime: stakingTrackerParams.MaxStakingTime,
MinStakingValue: stakingTrackerParams.MinStakingValue,
MaxStakingValue: stakingTrackerParams.MaxStakingValue,
}, nil
}

Expand Down Expand Up @@ -447,11 +457,6 @@ func (bc *BabylonController) QueryStakingTracker() (*StakingTrackerResponse, err
return nil, err
}

slashingAddress, err := btcutil.DecodeAddress(response.Params.SlashingAddress, bc.btcParams)
if err != nil {
return nil, err
}

// check this early than covenant config makes sense, so that rest of the
// code can assume that:
// 1. covenant quorum is less or equal to number of covenant pks
Expand All @@ -474,18 +479,43 @@ func (bc *BabylonController) QueryStakingTracker() (*StakingTrackerResponse, err
covenantPks = append(covenantPks, covenantBtcPk)
}

if response.Params.MinUnbondingTime > math.MaxUint16 {
if response.Params.MinUnbondingTimeBlocks > math.MaxUint16 {
return nil, fmt.Errorf("min unbonding time is bigger than uint16: %w", ErrInvalidValueReceivedFromBabylonNode)
}

if response.Params.MinStakingTimeBlocks > math.MaxUint16 {
return nil, fmt.Errorf("min staking time is bigger than uint16: %w", ErrInvalidValueReceivedFromBabylonNode)
}

if response.Params.MaxStakingTimeBlocks > math.MaxUint16 {
return nil, fmt.Errorf("max staking time is bigger than uint16: %w", ErrInvalidValueReceivedFromBabylonNode)
}

if response.Params.MinStakingValueSat < 0 {
return nil, fmt.Errorf("min staking value is negative: %w", ErrInvalidValueReceivedFromBabylonNode)
}

if response.Params.MaxStakingValueSat < 0 {
return nil, fmt.Errorf("max staking value is negative: %w", ErrInvalidValueReceivedFromBabylonNode)
}

if response.Params.UnbondingFeeSat < 0 {
return nil, fmt.Errorf("unbonding fee is negative: %w", ErrInvalidValueReceivedFromBabylonNode)
}

return &StakingTrackerResponse{
SlashingAddress: slashingAddress,
SlashingPkScript: response.Params.SlashingPkScript,
SlashingRate: response.Params.SlashingRate,
MinComissionRate: response.Params.MinCommissionRate,
CovenantPks: covenantPks,
MinSlashingFee: btcutil.Amount(response.Params.MinSlashingTxFeeSat),
CovenantQuruomThreshold: response.Params.CovenantQuorum,
MinUnbodningTime: uint16(response.Params.MinUnbondingTime),
MinUnbondingTime: uint16(response.Params.MinUnbondingTimeBlocks),
UnbondingFee: btcutil.Amount(response.Params.UnbondingFeeSat),
MinStakingTime: uint16(response.Params.MinStakingTimeBlocks),
MaxStakingTime: uint16(response.Params.MaxStakingTimeBlocks),
MinStakingValue: btcutil.Amount(response.Params.MinStakingValueSat),
MaxStakingValue: btcutil.Amount(response.Params.MaxStakingValueSat),
}, nil
}

Expand Down
28 changes: 25 additions & 3 deletions babylonclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
pv "github.com/cosmos/relayer/v2/relayer/provider"
Expand All @@ -27,8 +28,8 @@ type StakingParams struct {
// Bitcoin public key of the current covenant
CovenantPks []*btcec.PublicKey

// Address to which slashing transactions are sent
SlashingAddress btcutil.Address
// PkScript that must be inserted in the slashing output of the slashing transaction
SlashingPkScript []byte

// The rate at which the staked funds will be slashed, expressed as a decimal.
SlashingRate sdkmath.LegacyDec
Expand All @@ -38,6 +39,21 @@ type StakingParams struct {

// Minimum unbonding time required by bayblon
MinUnbondingTime uint16

// Fee required by unbonding transaction
UnbondingFee btcutil.Amount

// Minimum staking time required by bayblon
MinStakingTime uint16

// Maximum staking time required by bayblon
MaxStakingTime uint16

// Minimum staking value required by bayblon
MinStakingValue btcutil.Amount

// Maximum staking value required by bayblon
MaxStakingValue btcutil.Amount
}

// SingleKeyCosmosKeyring represents a keyring that supports only one pritvate/public key pair
Expand Down Expand Up @@ -154,6 +170,12 @@ func GetMockClient() *MockBabylonClient {

slashingAddress, _ := btcutil.NewAddressPubKey(covenantPk.PubKey().SerializeCompressed(), &chaincfg.SimNetParams)

slashingPkScript, err := txscript.PayToAddrScript(slashingAddress)

if err != nil {
panic(err)
}

fpBtcPrivKey, err := btcec.NewPrivateKey()
if err != nil {
panic(err)
Expand All @@ -170,7 +192,7 @@ func GetMockClient() *MockBabylonClient {
FinalizationTimeoutBlocks: 5,
MinSlashingTxFeeSat: btcutil.Amount(1000),
CovenantPks: []*btcec.PublicKey{covenantPk.PubKey()},
SlashingAddress: slashingAddress,
SlashingPkScript: slashingPkScript,
SlashingRate: sdkmath.LegacyNewDecWithPrec(1, 1), // 1 * 10^{-1} = 0.1
},
babylonKey: priv,
Expand Down
Loading