datagen

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 44 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRandomSeedsToFuzzer

func AddRandomSeedsToFuzzer(f *testing.F, num uint)

func BlockCreationResultToProofs

func BlockCreationResultToProofs(inputs []*BlockCreationResult) []*btcctypes.BTCSpvProof

func CreatOpReturnTransaction

func CreatOpReturnTransaction(r *rand.Rand, babylonData []byte) *wire.MsgTx

func GenRandomAccWithBalance

func GenRandomAccWithBalance(n int) ([]authtypes.GenesisAccount, []banktypes.Balance)

func GenRandomBTCHeaderBits

func GenRandomBTCHeaderBits(r *rand.Rand) uint32

GenRandomBTCHeaderBits constructs a random uint32 corresponding to BTC header difficulty bits

func GenRandomBTCHeaderBytes

func GenRandomBTCHeaderBytes(r *rand.Rand, parent *btclightclienttypes.BTCHeaderInfo, bitsBig *sdkmath.Uint) bbn.BTCHeaderBytes

GenRandomBTCHeaderBytes generates a random BTCHeaderBytes object based on randomly generated BTC header attributes If the `parent` argument is not `nil`, then the `PrevBlock` attribute of the BTC header will point to the hash of the parent and the `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 GenRandomBTCHeaderInfo

func GenRandomBTCHeaderInfo(r *rand.Rand) *btclightclienttypes.BTCHeaderInfo

GenRandomBTCHeaderInfo generates a random BTCHeaderInfo object

func GenRandomBTCHeaderInfoWithBits

func GenRandomBTCHeaderInfoWithBits(r *rand.Rand, bits *sdkmath.Uint) *btclightclienttypes.BTCHeaderInfo

func GenRandomBTCHeaderInfoWithInvalidHeader

func GenRandomBTCHeaderInfoWithInvalidHeader(r *rand.Rand, powLimit *big.Int) *btclightclienttypes.BTCHeaderInfo

func GenRandomBTCHeaderInfoWithParent

func GenRandomBTCHeaderInfoWithParent(r *rand.Rand, parent *btclightclienttypes.BTCHeaderInfo) *btclightclienttypes.BTCHeaderInfo

GenRandomBTCHeaderInfoWithParent generates a random BTCHeaderInfo object in which the parent points to the `parent` parameter.

func GenRandomBTCHeaderInfoWithParentAndBits

func GenRandomBTCHeaderInfoWithParentAndBits(r *rand.Rand, parent *btclightclienttypes.BTCHeaderInfo, bits *sdkmath.Uint) *btclightclienttypes.BTCHeaderInfo

GenRandomBTCHeaderInfoWithParentAndBits generates a BTCHeaderInfo object in which the `header.PrevBlock` points to the `parent` and the `Work` property points to the accumulated work (parent.Work + header.Work). Less bits as a parameter, means more difficulty.

func GenRandomBTCHeaderMerkleRoot

func GenRandomBTCHeaderMerkleRoot(r *rand.Rand) *chainhash.Hash

GenRandomBTCHeaderMerkleRoot generates a random hex string corresponding to a merkle root

func GenRandomBTCHeaderNonce

func GenRandomBTCHeaderNonce(r *rand.Rand) uint32

GenRandomBTCHeaderNonce generates a random BTC header nonce

func GenRandomBTCHeaderPrevBlock

func GenRandomBTCHeaderPrevBlock(r *rand.Rand) *bbn.BTCHeaderHashBytes

GenRandomBTCHeaderPrevBlock constructs a random BTCHeaderHashBytes instance

func GenRandomBTCHeaderTimestamp

func GenRandomBTCHeaderTimestamp(r *rand.Rand) time.Time

GenRandomBTCHeaderTimestamp generates a random BTC header timestamp

func GenRandomBTCHeaderVersion

func GenRandomBTCHeaderVersion(r *rand.Rand) int32

GenRandomBTCHeaderVersion generates a random version integer

func GenRandomBTCHeight

func GenRandomBTCHeight(r *rand.Rand) uint64

GenRandomBTCHeight returns a random uint64

func GenRandomBabylonTx

func GenRandomBabylonTx(r *rand.Rand) *wire.MsgTx

func GenRandomBabylonTxPair

func GenRandomBabylonTxPair(r *rand.Rand) ([]*wire.MsgTx, *btctxformatter.RawBtcCheckpoint)

func GenRandomBitmap

func GenRandomBitmap(r *rand.Rand) (bitmap.Bitmap, int)

GenRandomBitmap generates a random bitmap for the validator set It returns a random bitmap and the number of validators in the subset

func GenRandomBlsMultiSig

func GenRandomBlsMultiSig(r *rand.Rand) bls12381.Signature

func GenRandomBtcdBlock

func GenRandomBtcdBlock(r *rand.Rand, numBabylonTxs int, prevHash *chainhash.Hash) (*wire.MsgBlock, *btctxformatter.RawBtcCheckpoint)

GenRandomBtcdBlock generates a random BTC block, which can include Babylon txs. Specifically, - when numBabylonTxs == 0 or numBabylonTxs > 2, it generates a BTC block with 3 random txs. - when numBabylonTxs == 1, it generates a BTC block with 2 random txs and a Babylon tx. - when numBabylonTxs == 2, it generates a BTC block with 1 random tx and 2 Babylon txs that constitute a raw BTC checkpoint. When numBabylonTxs == 2, the function will return the BTC raw checkpoint as well.

func GenRandomBtcdBlockchainWithBabylonTx

func GenRandomBtcdBlockchainWithBabylonTx(r *rand.Rand, n uint64, oneTxThreshold float32, twoTxThreshold float32) ([]*wire.MsgBlock, int, []*btctxformatter.RawBtcCheckpoint)

GenRandomBtcdBlockchainWithBabylonTx generates a blockchain of `n` blocks, in which each block has some probability of including some Babylon txs Specifically, each block - has `oneTxThreshold` probability of including 1 Babylon tx that does not has any match - has `twoTxThreshold - oneTxThreshold` probability of including 2 Babylon txs that constitute a checkpoint - has `1 - twoTxThreshold` probability of including no Babylon tx

func GenRandomBtcdHash

func GenRandomBtcdHash(r *rand.Rand) chainhash.Hash

GenRandomBtcdHash generates a random hash in type `chainhash.Hash`, without any hash operations

func GenRandomBtcdHeader

func GenRandomBtcdHeader(r *rand.Rand) *wire.BlockHeader

func GenRandomByteArray

func GenRandomByteArray(r *rand.Rand, length uint64) []byte

func GenRandomEpoch

func GenRandomEpoch(r *rand.Rand) *epochingtypes.Epoch

func GenRandomEpochInterval

func GenRandomEpochInterval(r *rand.Rand) uint64

func GenRandomEpochNum

func GenRandomEpochNum(r *rand.Rand) uint64

func GenRandomHexStr

func GenRandomHexStr(r *rand.Rand, length uint64) string

func GenRandomIBCTMHeader

func GenRandomIBCTMHeader(r *rand.Rand, chainID string, height uint64) *ibctmtypes.Header

func GenRandomLastCommitHash

func GenRandomLastCommitHash(r *rand.Rand) types.LastCommitHash

func GenRandomPubkeysAndSigs

func GenRandomPubkeysAndSigs(n int, msg []byte) ([]bls12381.PublicKey, []bls12381.Signature)

func GenRandomRawCheckpoint

func GenRandomRawCheckpoint(r *rand.Rand) *types.RawCheckpoint

func GenRandomRawCheckpointWithMeta

func GenRandomRawCheckpointWithMeta(r *rand.Rand) *types.RawCheckpointWithMeta

func GenRandomSequenceRawCheckpointsWithMeta

func GenRandomSequenceRawCheckpointsWithMeta(r *rand.Rand) []*types.RawCheckpointWithMeta

GenRandomSequenceRawCheckpointsWithMeta generates random checkpoints from epoch 0 to a random epoch

func GenRandomStatus

func GenRandomStatus(r *rand.Rand) types.CheckpointStatus

GenRandomStatus generates random status except for Finalized

func GenRandomTMHeader

func GenRandomTMHeader(r *rand.Rand, chainID string, height uint64) *tmproto.Header

func GenRandomTx

func GenRandomTx(r *rand.Rand) *wire.MsgTx

func GenRandomValSet

func GenRandomValSet(n int) epochingtypes.ValidatorSet

func GenRandomValidBTCHeaderInfoWithParent

func GenRandomValidBTCHeaderInfoWithParent(r *rand.Rand, parent btclightclienttypes.BTCHeaderInfo) *btclightclienttypes.BTCHeaderInfo

GenRandomValidBTCHeaderInfoWithParent generates random BTCHeaderInfo object with valid proof of work. WARNING: if parent is from network with a lot of work (mainnet) it may never finish use only with simnet headers

func GenRandomValidatorAddress added in v0.6.0

func GenRandomValidatorAddress() sdk.ValAddress

func GenSequenceRawCheckpointsWithMeta

func GenSequenceRawCheckpointsWithMeta(r *rand.Rand, tipEpoch uint64) []*types.RawCheckpointWithMeta

func GenerateBLSSigs

func GenerateBLSSigs(keys []bls12381.PrivateKey, msg []byte) []bls12381.Signature

func GenerateGenesisKey

func GenerateGenesisKey() *types.GenesisKey

func GenerateLegitimateRawCheckpoint

func GenerateLegitimateRawCheckpoint(r *rand.Rand, privKeys []bls12381.PrivateKey) *types.RawCheckpoint

func GenerateMessageWithRandomSubmitter

func GenerateMessageWithRandomSubmitter(blockResults []*BlockCreationResult) *btcctypes.MsgInsertBTCSpvProof

func GenerateMessageWithRandomSubmitterForEpoch

func GenerateMessageWithRandomSubmitterForEpoch(r *rand.Rand, epoch uint64) *btcctypes.MsgInsertBTCSpvProof

func GetRandomRawBtcCheckpoint

func GetRandomRawBtcCheckpoint(r *rand.Rand) *btctxformatter.RawBtcCheckpoint

func HeaderToHeaderInfo added in v0.6.0

func HeaderToHeaderInfo(header *ibctmtypes.Header) *extendedkeeper.HeaderInfo

func InitializeNodeValidatorFiles

func InitializeNodeValidatorFiles(config *cfg.Config, addr sdk.AccAddress) (string, *privval.ValidatorKeys, error)

InitializeNodeValidatorFiles creates private validator and p2p configuration files.

func InitializeNodeValidatorFilesFromMnemonic

func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic string, addr sdk.AccAddress) (nodeID string, valKeys *privval.ValidatorKeys, err error)

func MutateHash

func MutateHash(r *rand.Rand, hash *bbn.BTCHeaderHashBytes) *bbn.BTCHeaderHashBytes

MutateHash takes a hash as a parameter, copies it, modifies the copy, and returns the copy.

func OneInN

func OneInN(r *rand.Rand, n int) bool

func RandomInt

func RandomInt(r *rand.Rand, rng int) uint64

func RandomIntOtherThan

func RandomIntOtherThan(r *rand.Rand, x int, rng int) uint64

func SolveBlock

func SolveBlock(header *wire.BlockHeader) bool

SolveBlock mutates provided header.Nonce, until it solves proof of work puzzle WARNING: providing header with too large difficulty (header.Bits) will make this function unfinishable.

func ValidHex

func ValidHex(hexStr string, length int) bool

ValidHex accepts a hex string and the length representation as a byte array

Types

type BTCHeaderTree

type BTCHeaderTree struct {
	// contains filtered or unexported fields
}

func NewBTCHeaderTree

func NewBTCHeaderTree() *BTCHeaderTree

func (*BTCHeaderTree) Add

Add adds a node into storage. If the `parent` is set, it is also added to the list of `parent`.

func (*BTCHeaderTree) Contains

func (t *BTCHeaderTree) Contains(node *blctypes.BTCHeaderInfo) bool

Contains checks whether a node is maintained in the internal storage

func (*BTCHeaderTree) GenRandomBTCHeaderTree

func (t *BTCHeaderTree) GenRandomBTCHeaderTree(r *rand.Rand, minHeight uint64, maxHeight uint64,
	parent *blctypes.BTCHeaderInfo, callback func(info *blctypes.BTCHeaderInfo) bool)

GenRandomBTCHeaderTree recursively generates a random tree of BTCHeaderInfo objects rooted at `parent`. The tree generation is accomplished by randomly selecting the number of children using the `RandNumChildren()`. Then, for each child, a random BTCHeaderInfo object is generated and a new tree rooted at that child is recursively generated. For each node that is generated, the callback function is invoked in order to identify whether we should continue generating or not as well as help with maintenance tasks (e.g. inserting headers into keeper storage).

func (*BTCHeaderTree) GetChildren

func (t *BTCHeaderTree) GetChildren(node *blctypes.BTCHeaderInfo) []*blctypes.BTCHeaderInfo

GetChildren returns the children of a node as a list of BTCHeaderInfo objects

func (*BTCHeaderTree) GetHeadersMap

func (t *BTCHeaderTree) GetHeadersMap() map[string]*blctypes.BTCHeaderInfo

GetHeadersMap returns a mapping between node hashes and nodes

func (*BTCHeaderTree) GetMainChain

func (t *BTCHeaderTree) GetMainChain() []*blctypes.BTCHeaderInfo

GetMainChain returns the tree fork with the most work

func (*BTCHeaderTree) GetNodeAncestry

func (t *BTCHeaderTree) GetNodeAncestry(node *blctypes.BTCHeaderInfo) []*blctypes.BTCHeaderInfo

GetNodeAncestry returns an ancestry list starting from the tree node and leading to the root of the tree.

func (*BTCHeaderTree) GetNodeAncestryUpTo

func (t *BTCHeaderTree) GetNodeAncestryUpTo(node *blctypes.BTCHeaderInfo,
	upTo *blctypes.BTCHeaderInfo) []*blctypes.BTCHeaderInfo

GetNodeAncestryUpTo returns an ancestry list starting from the tree node and leading to a child of the `upTo` parameter if it is not nil.

func (*BTCHeaderTree) GetNodeDescendants

func (t *BTCHeaderTree) GetNodeDescendants(node *blctypes.BTCHeaderInfo) []*blctypes.BTCHeaderInfo

GetNodeDescendants returns a list of the descendants of a node

func (*BTCHeaderTree) GetParent

GetParent returns the parent of the node, or nil if it doesn't exist

func (*BTCHeaderTree) GetRoot

func (t *BTCHeaderTree) GetRoot() *blctypes.BTCHeaderInfo

GetRoot returns the root of the tree -- i.e. the node without an existing parent

func (*BTCHeaderTree) GetTip

func (t *BTCHeaderTree) GetTip() *blctypes.BTCHeaderInfo

GetTip returns the header in the tree with the most work

func (*BTCHeaderTree) IsOnNodeChain

func (t *BTCHeaderTree) IsOnNodeChain(node *blctypes.BTCHeaderInfo, ancestor *blctypes.BTCHeaderInfo) bool

IsOnNodeChain returns true or false depending on whether the node is equal or a descendant of the `ancestor` parameter.

func (*BTCHeaderTree) RandNumChildren

func (t *BTCHeaderTree) RandNumChildren(r *rand.Rand, zeroChildrenAllowed bool) int

RandNumChildren randomly generates 0-2 children with the following probabilities: If zeroChildrenAllowed is not set:

1 child:    75%
2 children: 25%

Otherwise,

0 children: 25%
1 child:    50%
2 children: 25%

func (*BTCHeaderTree) RandomAncestor

func (t *BTCHeaderTree) RandomAncestor(r *rand.Rand, node *blctypes.BTCHeaderInfo) *blctypes.BTCHeaderInfo

RandomAncestor retrieves the ancestry list and returns an ancestor from it. Can include the node itself.

func (*BTCHeaderTree) RandomDescendant

func (t *BTCHeaderTree) RandomDescendant(r *rand.Rand, node *blctypes.BTCHeaderInfo) *blctypes.BTCHeaderInfo

RandomDescendant returns a random descendant of the node

func (*BTCHeaderTree) RandomNode

func (t *BTCHeaderTree) RandomNode(r *rand.Rand) *blctypes.BTCHeaderInfo

RandomNode selects a random header from the list of nodes

func (*BTCHeaderTree) Size

func (t *BTCHeaderTree) Size() int

Size returns the number of nodes that are maintained

type BlockCreationResult

type BlockCreationResult struct {
	HeaderBytes  bbn.BTCHeaderBytes
	Transactions []string
	BbnTxIndex   uint32
}

func CreateBlock

func CreateBlock(
	r *rand.Rand,
	height uint32,
	numTx uint32,
	babylonOpReturnIdx uint32,
	babylonData []byte,
) *BlockCreationResult

type BtcHeaderWithProof

type BtcHeaderWithProof struct {
	HeaderBytes bbn.BTCHeaderBytes
	SpvProof    *btcctypes.BTCSpvProof
}

func CreateBlockWithTransaction

func CreateBlockWithTransaction(
	r *rand.Rand,
	ph *wire.BlockHeader,
	babylonData []byte,
) *BtcHeaderWithProof

type PV

type PV struct {
	PrivKey cryptotypes.PrivKey
}

PV implements PrivValidator without any safety or persistence. Only use it for testing.

func NewPV

func NewPV() PV

func (PV) GetPubKey

func (pv PV) GetPubKey() (crypto.PubKey, error)

GetPubKey implements PrivValidator interface

func (PV) SignProposal

func (pv PV) SignProposal(chainID string, proposal *tmproto.Proposal) error

SignProposal implements PrivValidator interface

func (PV) SignVote

func (pv PV) SignVote(chainID string, vote *tmproto.Vote) error

SignVote implements PrivValidator interface

type TestRawCheckpointData

type TestRawCheckpointData struct {
	Epoch            uint64
	FirstPart        []byte
	SecondPart       []byte
	ExpectedOpReturn []byte
}

func EncodeRawCkptToTestData

func EncodeRawCkptToTestData(rawBTCCkpt *txformat.RawBtcCheckpoint) *TestRawCheckpointData

func RandomRawCheckpointDataForEpoch

func RandomRawCheckpointDataForEpoch(r *rand.Rand, e uint64) (*TestRawCheckpointData, *txformat.RawBtcCheckpoint)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL