Skip to content

Commit

Permalink
Rename functions in global namespace to have the BTC prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
vitsalis committed Jul 14, 2022
1 parent 6638fcd commit 6a7d8a3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions types/btcutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/btcsuite/btcd/wire"
)

// ValidateHeader
// ValidateBTCHeader
// Perform the checks that [checkBlockHeaderSanity](https://github.com/btcsuite/btcd/blob/master/blockchain/validate.go#L430) of btcd does
//
// We skip the "timestamp should not be 2 hours into the future" check
// since this might introduce undeterministic behavior
func ValidateHeader(header *wire.BlockHeader, powLimit *big.Int) error {
func ValidateBTCHeader(header *wire.BlockHeader, powLimit *big.Int) error {
msgBlock := &wire.MsgBlock{Header: *header}

block := btcutil.NewBlock(msgBlock)
Expand All @@ -38,20 +38,20 @@ func ValidateHeader(header *wire.BlockHeader, powLimit *big.Int) error {
return nil
}

func GetBaseHeaderHex() string {
func GetBaseBTCHeaderHex() string {
// TODO: get this from a configuration file
hex := "00006020c6c5a20e29da938a252c945411eba594cbeba021a1e20000000000000000000039e4bd0cd0b5232bb380a9576fcfe7d8fb043523f7a158187d9473e44c1740e6b4fa7c62ba01091789c24c22"
return hex
}

func GetBaseHeaderHeight() uint64 {
func GetBaseBTCHeaderHeight() uint64 {
// TODO: get this from a configuration file
height := uint64(736056)
return height
}

func GetBaseHeaderBytes() BTCHeaderBytes {
hex := GetBaseHeaderHex()
func GetBaseBTCHeaderBytes() BTCHeaderBytes {
hex := GetBaseBTCHeaderHex()
headerBytes, err := NewBTCHeaderBytesFromHex(hex)
if err != nil {
panic("Base BTC header hex cannot be converted to bytes")
Expand Down
4 changes: 2 additions & 2 deletions types/btcutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *btcutilsTestSuite) SetupSuite() {
s.testnetPowLimit = btcchaincfg.TestNet3Params.PowLimit
}

func (s *btcutilsTestSuite) TestValidateHeader() {
func (s *btcutilsTestSuite) TestValidateBTCHeader() {
data := []struct {
name string
header *wire.BlockHeader
Expand All @@ -53,7 +53,7 @@ func (s *btcutilsTestSuite) TestValidateHeader() {
}

for _, d := range data {
err := types.ValidateHeader(d.header, d.powLimit)
err := types.ValidateBTCHeader(d.header, d.powLimit)
if d.hasErr {
s.Require().Error(err, d.name)
} else {
Expand Down
2 changes: 1 addition & 1 deletion x/btccheckpoint/btcutils/btcutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func ParseProof(

header := types.BTCHeaderBytes(btcHeader).ToBlockHeader()

e = types.ValidateHeader(header, powLimit)
e = types.ValidateBTCHeader(header, powLimit)

if e != nil {
return nil, e
Expand Down
4 changes: 2 additions & 2 deletions x/btclightclient/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

func TestGenesis(t *testing.T) {
headerBytes := bbl.GetBaseHeaderBytes()
headerHeight := bbl.GetBaseHeaderHeight()
headerBytes := bbl.GetBaseBTCHeaderBytes()
headerHeight := bbl.GetBaseBTCHeaderHeight()
headerHash := headerBytes.Hash()
headerWork := types.CalcWork(&headerBytes)
baseHeaderInfo := types.NewBTCHeaderInfo(&headerBytes, headerHash, headerHeight, &headerWork)
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/btc_header_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func FuzzNewHeaderInfo(f *testing.F) {
defaultHeader := bbl.GetBaseHeaderBytes()
defaultHeader := bbl.GetBaseBTCHeaderBytes()
btcdHeader := defaultHeader.ToBlockHeader()
f.Add(
btcdHeader.Version,
Expand Down
4 changes: 2 additions & 2 deletions x/btclightclient/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
headerBytes := bbl.GetBaseHeaderBytes()
headerHeight := bbl.GetBaseHeaderHeight()
headerBytes := bbl.GetBaseBTCHeaderBytes()
headerHeight := bbl.GetBaseBTCHeaderHeight()
headerHash := headerBytes.Hash()
// The cumulative work for the Base BTC header is only the work
// for that particular header. This means that it is very important
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (msg *MsgInsertHeader) ValidateBasic() error {
}

func (msg *MsgInsertHeader) ValidateHeader(powLimit *big.Int) error {
return bbl.ValidateHeader(msg.Header.ToBlockHeader(), powLimit)
return bbl.ValidateBTCHeader(msg.Header.ToBlockHeader(), powLimit)
}

func (msg *MsgInsertHeader) GetSigners() []sdk.AccAddress {
Expand Down
2 changes: 1 addition & 1 deletion x/btclightclient/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func FuzzMsgInsertHeader(f *testing.F) {
addressBytes := []byte("from________________")
defaultHeader := bbl.GetBaseHeaderBytes()
defaultHeader := bbl.GetBaseBTCHeaderBytes()
defaultBtcdHeader := defaultHeader.ToBlockHeader()

// Maximum btc difficulty possible
Expand Down
4 changes: 2 additions & 2 deletions x/btclightclient/types/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestNewQueryParamsRequest(t *testing.T) {
}

func TestNewQueryHashesRequest(t *testing.T) {
headerBytes := bbl.GetBaseHeaderBytes()
headerBytes := bbl.GetBaseBTCHeaderBytes()
headerHashBytes := headerBytes.Hash()
req := query.PageRequest{
Key: headerHashBytes.MustMarshal(),
Expand Down Expand Up @@ -68,7 +68,7 @@ func FuzzNewQueryContainsRequest(f *testing.F) {
}

func TestNewQueryMainChainRequest(t *testing.T) {
headerBytes := bbl.GetBaseHeaderBytes()
headerBytes := bbl.GetBaseBTCHeaderBytes()
req := query.PageRequest{
Key: headerBytes.MustMarshal(),
}
Expand Down

0 comments on commit 6a7d8a3

Please sign in to comment.