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

Functionality for building custom mainnet tags #157

Merged
merged 2 commits into from
Sep 27, 2022
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
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (ao EmptyAppOptions) Get(o string) interface{} {
}

if o == "btc-config.checkpoint-tag" {
return txformat.MainTagStr
return txformat.DefaultMainTagStr
}

return nil
Expand Down
12 changes: 7 additions & 5 deletions btctxformatter/bbnformatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ package btctxformatter
// in some separate document/config

const (
MainTagStr string = "bbnm"

mainTagPrefix string = "bbn"
testTagPrefix string = "bbt"

DefautTestTagStr string = testTagPrefix + "0"
DefaultTestTagStr string = testTagPrefix + "0"
DefaultMainTagStr string = testTagPrefix + "m"
)

func MainTag() BabylonTag {
return BabylonTag([]byte(MainTagStr))
func MainTag(idx uint8) BabylonTag {
bytes := []byte(mainTagPrefix)
bytes = append(bytes, idx)
return BabylonTag(bytes)
}

func TestTag(idx uint8) BabylonTag {
Expand Down
10 changes: 5 additions & 5 deletions btctxformatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package btctxformatter

import (
"bytes"
"crypto/rand"
"math/rand"
"testing"
)

Expand Down Expand Up @@ -93,11 +93,11 @@ func FuzzEncodingDecoding(f *testing.F) {

// This fuzzer checks if decoder won't panic with whatever bytes we point it at
func FuzzDecodingWontPanic(f *testing.F) {
f.Add(randNBytes(firstPartLength))
f.Add(randNBytes(secondPartLength))
f.Add(randNBytes(firstPartLength), uint8(rand.Intn(99)))
f.Add(randNBytes(secondPartLength), uint8(rand.Intn(99)))

f.Fuzz(func(t *testing.T, bytes []byte) {
decoded, err := IsBabylonCheckpointData(MainTag(), CurrentVersion, bytes)
f.Fuzz(func(t *testing.T, bytes []byte, tagIdx uint8) {
decoded, err := IsBabylonCheckpointData(MainTag(tagIdx), CurrentVersion, bytes)

if err == nil {
if decoded.Index != 0 && decoded.Index != 1 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/babylond/cmd/custom_babylon_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type BtcConfig struct {
func defaultBabylonBtcConfig() BtcConfig {
return BtcConfig{
Network: string(bbn.BtcMainnet),
CheckpointTag: string(txformat.MainTagStr),
CheckpointTag: string(txformat.DefaultMainTagStr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/babylond/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Example:
cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")
// btccheckpoint args
cmd.Flags().String(flagBtcNetwork, string(bbn.BtcSimnet), "Bitcoin network to use. Available networks: simnet, testnet, mainnet")
cmd.Flags().String(flagBtcCheckpointTag, string(txformat.DefautTestTagStr), "Tag to use for Bitcoin checkpoints.")
cmd.Flags().String(flagBtcCheckpointTag, string(txformat.DefaultTestTagStr), "Tag to use for Bitcoin checkpoints.")
cmd.Flags().Uint64(flagBtcConfirmationDepth, 6, "Confirmation depth for Bitcoin headers.")
cmd.Flags().Uint64(flagBtcFinalizationTimeout, 20, "Finalization timeout for Bitcoin headers.")
// epoch args
Expand Down
2 changes: 1 addition & 1 deletion test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestSubmitCheckpoint(t *testing.T) {
}

p1, p2 := txformat.MustEncodeCheckpointData(
txformat.BabylonTag(txformat.DefautTestTagStr),
txformat.BabylonTag(txformat.DefaultTestTagStr),
txformat.CurrentVersion,
rawBtcCheckpoint,
)
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/btccheckpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewBTCCheckpointKeeper(
ek,
powLimit,
// use MainTag tests
txformat.MainTag(),
txformat.MainTag(0),
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
14 changes: 8 additions & 6 deletions x/btccheckpoint/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func getRandomCheckpointDataForEpoch(e uint64) testCheckpointData {
}

// both f and s must be parts retrived from txformat.Encode
func getExpectedOpReturn(f []byte, s []byte) []byte {
func getExpectedOpReturn(tag txformat.BabylonTag, f []byte, s []byte) []byte {
firstPartNoHeader, err := txformat.GetCheckpointData(
txformat.MainTag(),
tag,
txformat.CurrentVersion,
0,
f,
Expand All @@ -78,7 +78,7 @@ func getExpectedOpReturn(f []byte, s []byte) []byte {
}

secondPartNoHeader, err := txformat.GetCheckpointData(
txformat.MainTag(),
tag,
txformat.CurrentVersion,
1,
s,
Expand All @@ -103,6 +103,7 @@ func TestSubmitValidNewCheckpoint(t *testing.T) {
defaultParams := btcctypes.DefaultParams()
kDeep := defaultParams.BtcConfirmationDepth
checkpointData := getRandomCheckpointDataForEpoch(epoch)
tag := txformat.MainTag(0)

rawBTCCkpt := &txformat.RawBtcCheckpoint{
Epoch: checkpointData.epoch,
Expand All @@ -112,15 +113,15 @@ func TestSubmitValidNewCheckpoint(t *testing.T) {
BlsSig: checkpointData.blsSig,
}
data1, data2 := txformat.MustEncodeCheckpointData(
txformat.MainTag(),
tag,
txformat.CurrentVersion,
rawBTCCkpt,
)

blck1 := dg.CreateBlock(1, 7, 7, data1)
blck2 := dg.CreateBlock(2, 14, 3, data2)

expectedOpReturn := getExpectedOpReturn(data1, data2)
expectedOpReturn := getExpectedOpReturn(tag, data1, data2)

// here we will only have valid unconfirmed submissions
lc := btcctypes.NewMockBTCLightClientKeeper(int64(kDeep) - 1)
Expand Down Expand Up @@ -193,6 +194,7 @@ func TestStateTransitionOfValidSubmission(t *testing.T) {
kDeep := defaultParams.BtcConfirmationDepth
wDeep := defaultParams.CheckpointFinalizationTimeout
checkpointData := getRandomCheckpointDataForEpoch(epoch)
tag := txformat.MainTag(0)

rawBTCCkpt := &txformat.RawBtcCheckpoint{
Epoch: checkpointData.epoch,
Expand All @@ -202,7 +204,7 @@ func TestStateTransitionOfValidSubmission(t *testing.T) {
BlsSig: checkpointData.blsSig,
}
data1, data2 := txformat.MustEncodeCheckpointData(
txformat.MainTag(),
tag,
txformat.CurrentVersion,
rawBTCCkpt,
)
Expand Down