Skip to content

Commit

Permalink
chore: Replace all instances of bbl with bbn (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitsalis authored Aug 30, 2022
1 parent c18ea46 commit d206af7
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 86 deletions.
4 changes: 2 additions & 2 deletions cmd/babylond/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/babylonchain/babylon/app"
bblcmd "github.com/babylonchain/babylon/cmd/babylond/cmd"
bbncmd "github.com/babylonchain/babylon/cmd/babylond/cmd"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)

cmd := bblcmd.AddGenesisAccountCmd(home)
cmd := bbncmd.AddGenesisAccountCmd(home)
cmd.SetArgs([]string{
tc.addr,
tc.denom,
Expand Down
Binary file modified docs/diagrams/btc_light_client.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/diagrams/database_schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/diagrams/submit_checkpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/diagrams/submit_checkpoint.puml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ queue Events

== Initialize Relayer ==

User -> CLI : bbld tx btccheckpoint \n register --key btc-key.pk
User -> CLI : bbnd tx btccheckpoint \n register --key btc-key.pk
CLI -> Tendermint : Broadcast tx
Tendermint -> Mempool : Add register tx

Expand Down Expand Up @@ -76,7 +76,7 @@ submitter -> Bitcoin -- : Broadcast 2 \n checkpoint transactions

... wait for checkpointing tx to be included in a Bitcoin block ...

Bitcoin --> submitter ++ : Observe BTC block \n with BBL checkpoints
Bitcoin --> submitter ++ : Observe BTC block \n with BBN checkpoints
submitter -> submitter : Construct BTC Proof-of-Inclusion
submitter -> Tendermint --++ : Broadcast InsertProofOfInclusion transaction

Expand Down
Binary file modified docs/diagrams/validator_registration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/diagrams/validator_registration.puml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ queue Events

== Create User Transaction ==

User -> CLI ++ : bbld tx staking create-validator ... \n --generate-only
User -> CLI ++ : bbnd tx staking create-validator ... \n --generate-only
return unsigned_staking_tx.json
User -> CLI ++ : bbld tx checkpointing create-validator \n ~--wrap unsigned_staking_tx.json \n ~--bls-key ... --generate-only
User -> CLI ++ : bbnd tx checkpointing create-validator \n ~--wrap unsigned_staking_tx.json \n ~--bls-key ... --generate-only
return unsigned_checkpointing_tx.json
User -> CLI ++ : bbld tx sign unsigned_checkpointing_tx.json
User -> CLI ++ : bbnd tx sign unsigned_checkpointing_tx.json
return signed_checkpointing_tx.json
User -> CLI : bbld tx broadcast signed_checkpointing_tx.json
User -> CLI : bbnd tx broadcast signed_checkpointing_tx.json

CLI -> Tendermint ++ : signed_checkpointing_tx
Tendermint -> checkpointing ++ : CheckTx
Expand Down
4 changes: 2 additions & 2 deletions testutil/datagen/btc_checkpoint.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package datagen

import (
bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
btcctypes "github.com/babylonchain/babylon/x/btccheckpoint/types"
)

func SpvProofFromHeaderAndTransactions(headerBytes []byte, transactions [][]byte, transactionIdx uint) (*btcctypes.BTCSpvProof, error) {
proof, e := bbl.CreateProofForIdx(transactions, transactionIdx)
proof, e := bbn.CreateProofForIdx(transactions, transactionIdx)

if e != nil {
return nil, e
Expand Down
20 changes: 10 additions & 10 deletions testutil/datagen/btc_header_info.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package datagen

import (
bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
btclightclienttypes "github.com/babylonchain/babylon/x/btclightclient/types"
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -47,9 +47,9 @@ func GenRandomBTCHeaderBits() uint32 {
}

// GenRandomBTCHeaderPrevBlock constructs a random BTCHeaderHashBytes instance
func GenRandomBTCHeaderPrevBlock() *bbl.BTCHeaderHashBytes {
hex := GenRandomHexStr(bbl.BTCHeaderHashLen)
hashBytes, _ := bbl.NewBTCHeaderHashBytesFromHex(hex)
func GenRandomBTCHeaderPrevBlock() *bbn.BTCHeaderHashBytes {
hex := GenRandomHexStr(bbn.BTCHeaderHashLen)
hashBytes, _ := bbn.NewBTCHeaderHashBytesFromHex(hex)
return &hashBytes
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func GenRandomBTCHeaderNonce() uint32 {
// `Timestamp` attribute will be later than the parent's `Timestamp`.
// If the `bitsBig` argument is not `nil`, then the `Bits` attribute
// of the BTC header will point to the compact form of big integer.
func GenRandomBTCHeaderBytes(parent *btclightclienttypes.BTCHeaderInfo, bitsBig *sdk.Uint) bbl.BTCHeaderBytes {
func GenRandomBTCHeaderBytes(parent *btclightclienttypes.BTCHeaderInfo, bitsBig *sdk.Uint) bbn.BTCHeaderBytes {
btcdHeader := GenRandomBtcdHeader()

if bitsBig != nil {
Expand All @@ -102,7 +102,7 @@ func GenRandomBTCHeaderBytes(parent *btclightclienttypes.BTCHeaderInfo, bitsBig
btcdHeader.Timestamp = parent.Header.Time().Add(time.Minute*10 + time.Duration(seconds)*time.Second)
}

return bbl.NewBTCHeaderBytesFromBlockHeader(btcdHeader)
return bbn.NewBTCHeaderBytesFromBlockHeader(btcdHeader)
}

// GenRandomBTCHeight returns a random uint64
Expand Down Expand Up @@ -148,13 +148,13 @@ func GenRandomBTCHeaderInfo() *btclightclienttypes.BTCHeaderInfo {
}

// MutateHash takes a hash as a parameter, copies it, modifies the copy, and returns the copy.
func MutateHash(hash *bbl.BTCHeaderHashBytes) *bbl.BTCHeaderHashBytes {
mutatedBytes := make([]byte, bbl.BTCHeaderHashLen)
func MutateHash(hash *bbn.BTCHeaderHashBytes) *bbn.BTCHeaderHashBytes {
mutatedBytes := make([]byte, bbn.BTCHeaderHashLen)
// Retrieve a random byte index
idx := RandomInt(bbl.BTCHeaderHashLen)
idx := RandomInt(bbn.BTCHeaderHashLen)
copy(mutatedBytes, hash.MustMarshal())
// Add one to the index
mutatedBytes[idx] += 1
mutated, _ := bbl.NewBTCHeaderHashBytesFromBytes(mutatedBytes)
mutated, _ := bbn.NewBTCHeaderHashBytesFromBytes(mutatedBytes)
return &mutated
}
4 changes: 2 additions & 2 deletions x/btccheckpoint/btcutils/btcutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/hex"
"testing"

bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
btcchaincfg "github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
)
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestParsingCorrectBtcProofs(t *testing.T) {
transactionBytes = append(transactionBytes, tb)
}

branch, _ := bbl.CreateProofForIdx(transactionBytes, uint(test.opReturnTransactionIdx))
branch, _ := bbn.CreateProofForIdx(transactionBytes, uint(test.opReturnTransactionIdx))

opReturnTx := transactionBytes[test.opReturnTransactionIdx]

Expand Down
10 changes: 5 additions & 5 deletions x/btccheckpoint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"math/big"

bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
"github.com/babylonchain/babylon/x/btccheckpoint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -65,16 +65,16 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

func (k Keeper) GetBlockHeight(ctx sdk.Context, b *bbl.BTCHeaderHashBytes) (uint64, error) {
func (k Keeper) GetBlockHeight(ctx sdk.Context, b *bbn.BTCHeaderHashBytes) (uint64, error) {
return k.btcLightClientKeeper.BlockHeight(ctx, b)
}

func (k Keeper) CheckHeaderIsKnown(ctx sdk.Context, hash *bbl.BTCHeaderHashBytes) bool {
func (k Keeper) CheckHeaderIsKnown(ctx sdk.Context, hash *bbn.BTCHeaderHashBytes) bool {
_, err := k.btcLightClientKeeper.MainChainDepth(ctx, hash)
return err == nil
}

func (k Keeper) MainChainDepth(ctx sdk.Context, hash *bbl.BTCHeaderHashBytes) (uint64, bool, error) {
func (k Keeper) MainChainDepth(ctx sdk.Context, hash *bbn.BTCHeaderHashBytes) (uint64, bool, error) {
depth, err := k.btcLightClientKeeper.MainChainDepth(ctx, hash)

if err != nil {
Expand All @@ -88,7 +88,7 @@ func (k Keeper) MainChainDepth(ctx sdk.Context, hash *bbl.BTCHeaderHashBytes) (u
return uint64(depth), true, nil
}

func (k Keeper) IsAncestor(ctx sdk.Context, parentHash *bbl.BTCHeaderHashBytes, childHash *bbl.BTCHeaderHashBytes) (bool, error) {
func (k Keeper) IsAncestor(ctx sdk.Context, parentHash *bbn.BTCHeaderHashBytes, childHash *bbn.BTCHeaderHashBytes) (bool, error) {
return k.btcLightClientKeeper.IsAncestor(ctx, parentHash, childHash)
}

Expand Down
8 changes: 4 additions & 4 deletions x/btccheckpoint/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand All @@ -22,15 +22,15 @@ type BTCLightClientKeeper interface {
// BlockHeight should validate if header with given hash is valid and if it is
// part of known chain. In case this is true it should return this block height
// in case this is false it should return error
BlockHeight(ctx sdk.Context, headerHash *bbl.BTCHeaderHashBytes) (uint64, error)
BlockHeight(ctx sdk.Context, headerHash *bbn.BTCHeaderHashBytes) (uint64, error)

// IsAncestor should check if childHash header is direct ancestor of parentHash
// if either of this header is not known to light clinet it should return error
IsAncestor(ctx sdk.Context, parentHash *bbl.BTCHeaderHashBytes, childHash *bbl.BTCHeaderHashBytes) (bool, error)
IsAncestor(ctx sdk.Context, parentHash *bbn.BTCHeaderHashBytes, childHash *bbn.BTCHeaderHashBytes) (bool, error)

// MainChainDepth returns the depth of the header in the main chain or -1 if it does not exist in it
// Error is returned if header is unknown to lightclient
MainChainDepth(ctx sdk.Context, headerBytes *bbl.BTCHeaderHashBytes) (int64, error)
MainChainDepth(ctx sdk.Context, headerBytes *bbn.BTCHeaderHashBytes) (int64, error)
}

type CheckpointingKeeper interface {
Expand Down
8 changes: 4 additions & 4 deletions x/btccheckpoint/types/mock_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"errors"

bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -57,16 +57,16 @@ func (mc *MockBTCLightClientKeeper) ReturnSuccess() {
mc.returnError = false
}

func (mb MockBTCLightClientKeeper) BlockHeight(ctx sdk.Context, header *bbl.BTCHeaderHashBytes) (uint64, error) {
func (mb MockBTCLightClientKeeper) BlockHeight(ctx sdk.Context, header *bbn.BTCHeaderHashBytes) (uint64, error) {
// todo not used
return uint64(10), nil
}

func (mb MockBTCLightClientKeeper) IsAncestor(ctx sdk.Context, parentHash *bbl.BTCHeaderHashBytes, childHash *bbl.BTCHeaderHashBytes) (bool, error) {
func (mb MockBTCLightClientKeeper) IsAncestor(ctx sdk.Context, parentHash *bbn.BTCHeaderHashBytes, childHash *bbn.BTCHeaderHashBytes) (bool, error) {
return true, nil
}

func (ck MockBTCLightClientKeeper) MainChainDepth(ctx sdk.Context, headerBytes *bbl.BTCHeaderHashBytes) (int64, error) {
func (ck MockBTCLightClientKeeper) MainChainDepth(ctx sdk.Context, headerBytes *bbn.BTCHeaderHashBytes) (int64, error) {
if ck.returnError {
return -1, errors.New("unknown header")
}
Expand Down
6 changes: 3 additions & 3 deletions x/btclightclient/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package btclightclient_test

import (
bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
"testing"

keepertest "github.com/babylonchain/babylon/testutil/keeper"
Expand All @@ -12,8 +12,8 @@ import (
)

func TestGenesis(t *testing.T) {
headerBytes := bbl.GetBaseBTCHeaderBytes()
headerHeight := bbl.GetBaseBTCHeaderHeight()
headerBytes := bbn.GetBaseBTCHeaderBytes()
headerHeight := bbn.GetBaseBTCHeaderHeight()
headerHash := headerBytes.Hash()
headerWork := types.CalcWork(&headerBytes)
baseHeaderInfo := types.NewBTCHeaderInfo(&headerBytes, headerHash, headerHeight, &headerWork)
Expand Down
11 changes: 5 additions & 6 deletions x/btclightclient/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package keeper

import (
"context"

bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
"github.com/babylonchain/babylon/x/btclightclient/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
Expand All @@ -26,13 +25,13 @@ func (k Keeper) Hashes(ctx context.Context, req *types.QueryHashesRequest) (*typ
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
var hashes []bbl.BTCHeaderHashBytes
var hashes []bbn.BTCHeaderHashBytes

sdkCtx := sdk.UnwrapSDKContext(ctx)

// Ensure that the pagination key corresponds to hash bytes
if len(req.Pagination.Key) != 0 {
_, err := bbl.NewBTCHeaderHashBytesFromBytes(req.Pagination.Key)
_, err := bbn.NewBTCHeaderHashBytesFromBytes(req.Pagination.Key)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -79,7 +78,7 @@ func (k Keeper) MainChain(ctx context.Context, req *types.QueryMainChainRequest)

var keyHeader *types.BTCHeaderInfo
if len(req.Pagination.Key) != 0 {
headerHash, err := bbl.NewBTCHeaderHashBytesFromBytes(req.Pagination.Key)
headerHash, err := bbn.NewBTCHeaderHashBytesFromBytes(req.Pagination.Key)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "key does not correspond to a header hash")
}
Expand All @@ -98,7 +97,7 @@ func (k Keeper) MainChain(ctx context.Context, req *types.QueryMainChainRequest)
// which requires starting at the end
mainchain := k.headersState(sdkCtx).GetMainChain()
// Reverse the mainchain -- we want to retrieve results starting from the base header
bbl.Reverse(mainchain)
bbn.Reverse(mainchain)
if keyHeader == nil {
keyHeader = baseHeader
start = 0
Expand Down
6 changes: 3 additions & 3 deletions x/btclightclient/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper_test

import (
"github.com/babylonchain/babylon/testutil/datagen"
bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
"github.com/cosmos/cosmos-sdk/types/query"
"math/rand"
"testing"
Expand Down Expand Up @@ -61,7 +61,7 @@ func FuzzHashesQuery(f *testing.F) {

// Test pagination key being invalid
// We want the key to have a positive length
bzSz := datagen.RandomIntOtherThan(bbl.BTCHeaderHashLen-1, bbl.BTCHeaderHashLen*10) + 1
bzSz := datagen.RandomIntOtherThan(bbn.BTCHeaderHashLen-1, bbn.BTCHeaderHashLen*10) + 1
key := datagen.GenRandomByteArray(bzSz)
pagination := constructRequestWithKey(key)
hashesRequest := types.NewQueryHashesRequest(pagination)
Expand Down Expand Up @@ -213,7 +213,7 @@ func FuzzMainChainQuery(f *testing.F) {

// Test pagination key being invalid
// We want the key to have a positive length
bzSz := datagen.RandomIntOtherThan(bbl.BTCHeaderHashLen-1, bbl.BTCHeaderHashLen*10) + 1
bzSz := datagen.RandomIntOtherThan(bbn.BTCHeaderHashLen-1, bbn.BTCHeaderHashLen*10) + 1
key := datagen.GenRandomByteArray(bzSz)
pagination := constructRequestWithKey(key)
mainchainRequest := types.NewQueryMainChainRequest(pagination)
Expand Down
12 changes: 6 additions & 6 deletions x/btclightclient/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package keeper

import (
"fmt"
bbl "github.com/babylonchain/babylon/types"
bbn "github.com/babylonchain/babylon/types"
"github.com/tendermint/tendermint/libs/log"

"github.com/babylonchain/babylon/x/btclightclient/types"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (k *Keeper) SetHooks(bh types.BTCLightClientHooks) *Keeper {
}

// InsertHeader inserts a btcd header into the header state
func (k Keeper) InsertHeader(ctx sdk.Context, header *bbl.BTCHeaderBytes) error {
func (k Keeper) InsertHeader(ctx sdk.Context, header *bbn.BTCHeaderBytes) error {
if header == nil {
return types.ErrEmptyMessage
}
Expand Down Expand Up @@ -143,15 +143,15 @@ func (k Keeper) InsertHeader(ctx sdk.Context, header *bbl.BTCHeaderBytes) error
}

// BlockHeight returns the height of the provided header
func (k Keeper) BlockHeight(ctx sdk.Context, headerHash *bbl.BTCHeaderHashBytes) (uint64, error) {
func (k Keeper) BlockHeight(ctx sdk.Context, headerHash *bbn.BTCHeaderHashBytes) (uint64, error) {
if headerHash == nil {
return 0, types.ErrEmptyMessage
}
return k.headersState(ctx).GetHeaderHeight(headerHash)
}

// MainChainDepth returns the depth of the header in the main chain or -1 if it does not exist in it
func (k Keeper) MainChainDepth(ctx sdk.Context, headerHashBytes *bbl.BTCHeaderHashBytes) (int64, error) {
func (k Keeper) MainChainDepth(ctx sdk.Context, headerHashBytes *bbn.BTCHeaderHashBytes) (int64, error) {
if headerHashBytes == nil {
return -1, types.ErrEmptyMessage
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (k Keeper) MainChainDepth(ctx sdk.Context, headerHashBytes *bbl.BTCHeaderHa
}

// IsHeaderKDeep returns true if a header is at least k-deep on the main chain
func (k Keeper) IsHeaderKDeep(ctx sdk.Context, headerHashBytes *bbl.BTCHeaderHashBytes, depth uint64) (bool, error) {
func (k Keeper) IsHeaderKDeep(ctx sdk.Context, headerHashBytes *bbn.BTCHeaderHashBytes, depth uint64) (bool, error) {
if headerHashBytes == nil {
return false, types.ErrEmptyMessage
}
Expand All @@ -203,7 +203,7 @@ func (k Keeper) IsHeaderKDeep(ctx sdk.Context, headerHashBytes *bbl.BTCHeaderHas

// IsAncestor returns true/false depending on whether `parent` is an ancestor of `child`.
// Returns false if the parent and the child are the same header.
func (k Keeper) IsAncestor(ctx sdk.Context, parentHashBytes *bbl.BTCHeaderHashBytes, childHashBytes *bbl.BTCHeaderHashBytes) (bool, error) {
func (k Keeper) IsAncestor(ctx sdk.Context, parentHashBytes *bbn.BTCHeaderHashBytes, childHashBytes *bbn.BTCHeaderHashBytes) (bool, error) {
// nil checks
if parentHashBytes == nil || childHashBytes == nil {
return false, types.ErrEmptyMessage
Expand Down
Loading

0 comments on commit d206af7

Please sign in to comment.