bor

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 17, 2020 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ShuffleRoundCount = 90

Variables

View Source
var (
	DefaultValue = []byte{0x01} // Value to store in CacheCheckpoint and CacheCheckpointACK & ValidatorSetChange Flag

	SpanDurationKey       = []byte{0x24} // Key to store span duration for Bor
	SprintDurationKey     = []byte{0x25} // Key to store span duration for Bor
	LastSpanIDKey         = []byte{0x35} // Key to store last span start block
	SpanPrefixKey         = []byte{0x36} // prefix key to store span
	SpanCacheKey          = []byte{0x37} // key to store Cache for span
	LastProcessedEthBlock = []byte{0x38} // key to store last processed eth block for seed
)

Functions

func ExportGenesis

func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState

ExportGenesis returns a GenesisState for a given context and keeper.

func GetSpanKey

func GetSpanKey(id uint64) []byte

GetSpanKey appends prefix to start block

func HandleMsgProposeSpan

func HandleMsgProposeSpan(ctx sdk.Context, msg types.MsgProposeSpan, k Keeper) sdk.Result

HandleMsgProposeSpan handles proposeSpan msg

func InitGenesis

func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState)

InitGenesis sets distribution information for genesis.

func NewHandler

func NewHandler(k Keeper) sdk.Handler

NewHandler returns a handler for "bor" type messages.

func NewPostTxHandler added in v0.1.7

func NewPostTxHandler(k Keeper, contractCaller helper.IContractCaller) hmTypes.PostTxHandler

NewPostTxHandler returns a side handler for "span" type messages.

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier creates a querier for auth REST endpoints

func NewSideTxHandler added in v0.1.7

func NewSideTxHandler(k Keeper, contractCaller helper.IContractCaller) hmTypes.SideTxHandler

NewSideTxHandler returns a side handler for "span" type messages.

func PostHandleMsgEventSpan added in v0.1.7

func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg types.MsgProposeSpan, sideTxResult abci.SideTxResultType) sdk.Result

PostHandleMsgEventSpan handles state persisting span msg

func SelectNextProducers

func SelectNextProducers(blkHash common.Hash, spanEligibleVals []hmTypes.Validator, producerCount uint64) (selectedIDs []uint64, err error)

SelectNextProducers selects producers for next span by converting power to tickets

func ShuffleList

func ShuffleList(input []uint64, seed [32]byte) ([]uint64, error)

ShuffleList returns list of shuffled indexes in a pseudorandom permutation `p` of `0...list_size - 1` with “seed“ as entropy. We utilize 'swap or not' shuffling in this implementation; we are allocating the memory with the seed that stays constant between iterations instead of reallocating it each iteration as in the spec. This implementation is based on the original implementation from protolambda, https://github.com/protolambda/eth2-shuffle

improvements:
 - seed is always the first 32 bytes of the hash input, we just copy it into the buffer one time.
 - add round byte to seed and hash that part of the buffer.
 - split up the for-loop in two:
  1. Handle the part from 0 (incl) to pivot (incl). This is mirrored around (pivot / 2).
  2. Handle the part from pivot (excl) to N (excl). This is mirrored around ((pivot / 2) + (size/2)).
 - hash source every 256 iterations.
 - change byteV every 8 iterations.
 - we start at the edges, and work back to the mirror point.
   this makes us process each pear exactly once (instead of unnecessarily twice, like in the spec).

func ShuffledIndex

func ShuffledIndex(index uint64, indexCount uint64, seed [32]byte) (uint64, error)

ShuffledIndex returns `p(index)` in a pseudorandom permutation `p` of `0...list_size - 1` with “seed“ as entropy. We utilize 'swap or not' shuffling in this implementation; we are allocating the memory with the seed that stays constant between iterations instead of reallocating it each iteration as in the spec. This implementation is based on the original implementation from protolambda, https://github.com/protolambda/eth2-shuffle

func SideHandleMsgSpan added in v0.1.7

func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg types.MsgProposeSpan, contractCaller helper.IContractCaller) (result abci.ResponseDeliverSideTx)

SideHandleMsgSpan validates external calls required for processing proposed span

func SplitIndices

func SplitIndices(l []uint64, n uint64) [][]uint64

SplitIndices splits a list into n pieces.

func SplitOffset

func SplitOffset(listSize uint64, chunks uint64, index uint64) uint64

SplitOffset returns (listsize * index) / chunks

Spec pseudocode definition: def get_split_offset(list_size: int, chunks: int, index: int) -> int:

"""
Returns a value such that for a list L, chunk count k and index i,
split(L, k)[i] == L[get_split_offset(len(L), k, i): get_split_offset(len(L), k, i+1)]
"""
return (list_size * index) // chunks

func ToBytes

func ToBytes(x uint64, length int) []byte

ToBytes returns integer x to bytes in little-endian format at the specified length. Spec pseudocode definition:

def int_to_bytes(integer: int, length: int) -> bytes:
  return integer.to_bytes(length, 'little')

func UnShuffledIndex

func UnShuffledIndex(index uint64, indexCount uint64, seed [32]byte) (uint64, error)

UnShuffledIndex returns the inverse of ShuffledIndex. This implementation is based on the original implementation from protolambda, https://github.com/protolambda/eth2-shuffle

func UnshuffleList

func UnshuffleList(input []uint64, seed [32]byte) ([]uint64, error)

UnshuffleList un-shuffles the list by running backwards through the round count.

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule implements an application module for the supply module.

func NewAppModule

func NewAppModule(keeper Keeper, contractCaller helper.IContractCaller) AppModule

NewAppModule creates a new AppModule object

func (AppModule) BeginBlock

func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock)

BeginBlock returns the begin blocker for the auth module.

func (AppModule) EndBlock

EndBlock returns the end blocker for the auth module. It returns no validator updates.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage

ExportGenesis returns the exported genesis state as raw bytes for the auth module.

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs genesis initialization for the auth module. It returns no validator updates.

func (AppModule) Name

func (AppModule) Name() string

Name returns the auth module's name.

func (AppModule) NewHandler

func (am AppModule) NewHandler() sdk.Handler

NewHandler returns an sdk.Handler for the module.

func (AppModule) NewPostTxHandler added in v0.1.7

func (am AppModule) NewPostTxHandler() hmTypes.PostTxHandler

NewPostTxHandler side tx handler

func (AppModule) NewQuerierHandler

func (am AppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler returns the auth module sdk.Querier.

func (AppModule) NewSideTxHandler added in v0.1.7

func (am AppModule) NewSideTxHandler() hmTypes.SideTxHandler

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute returns the auth module's querier route name.

func (AppModule) RegisterInvariants

func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry)

RegisterInvariants performs a no-op.

func (AppModule) Route

func (AppModule) Route() string

Route returns the message routing key for the auth module.

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic defines the basic application module used by the auth module.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis() json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the auth module.

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command

GetQueryCmd returns the root query command for the auth module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command

GetTxCmd returns the root tx command for the auth module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name returns the auth module's name.

func (AppModuleBasic) RegisterCodec

func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)

RegisterCodec registers the auth module's types for the given codec.

func (AppModuleBasic) RegisterRESTRoutes

func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router)

RegisterRESTRoutes registers the REST routes for the auth module.

func (AppModuleBasic) ValidateGenesis

func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error

ValidateGenesis performs genesis state validation for the auth module.

func (AppModuleBasic) VerifyGenesis

func (AppModuleBasic) VerifyGenesis(bz map[string]json.RawMessage) error

VerifyGenesis performs verification on auth module state.

type Keeper

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

Keeper stores all related data

func NewKeeper

func NewKeeper(
	cdc *codec.Codec,
	storeKey sdk.StoreKey,
	paramSpace subspace.Subspace,
	codespace sdk.CodespaceType,
	chainKeeper chainmanager.Keeper,
	stakingKeeper staking.Keeper,
	caller helper.ContractCaller,
) Keeper

NewKeeper create new keeper

func (*Keeper) AddNewRawSpan

func (k *Keeper) AddNewRawSpan(ctx sdk.Context, span hmTypes.Span) error

AddNewRawSpan adds new span for bor to store

func (*Keeper) AddNewSpan

func (k *Keeper) AddNewSpan(ctx sdk.Context, span hmTypes.Span) error

AddNewSpan adds new span for bor to store

func (Keeper) Codespace

func (k Keeper) Codespace() sdk.CodespaceType

Codespace returns the codespace

func (*Keeper) FreezeSet

func (k *Keeper) FreezeSet(ctx sdk.Context, id uint64, startBlock uint64, endBlock uint64, borChainID string, seed common.Hash) error

FreezeSet freezes validator set for next span

func (*Keeper) GetAllSpans

func (k *Keeper) GetAllSpans(ctx sdk.Context) (spans []*hmTypes.Span)

GetAllSpans fetches all indexed by id from store

func (*Keeper) GetLastEthBlock

func (k *Keeper) GetLastEthBlock(ctx sdk.Context) *big.Int

GetLastEthBlock get last processed Eth block for seed

func (*Keeper) GetLastSpan

func (k *Keeper) GetLastSpan(ctx sdk.Context) (*hmTypes.Span, error)

GetLastSpan fetches last span using lastStartBlock

func (Keeper) GetNextSpanSeed added in v0.1.7

func (k Keeper) GetNextSpanSeed(ctx sdk.Context) (common.Hash, error)

func (*Keeper) GetParams

func (k *Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams gets the bor module's parameters.

func (*Keeper) GetSpan

func (k *Keeper) GetSpan(ctx sdk.Context, id uint64) (*hmTypes.Span, error)

GetSpan fetches span indexed by id from store

func (*Keeper) GetSpanList

func (k *Keeper) GetSpanList(ctx sdk.Context, page uint64, limit uint64) ([]hmTypes.Span, error)

GetSpanList returns all spans with params like page and limit

func (*Keeper) HasSpan added in v0.1.7

func (k *Keeper) HasSpan(ctx sdk.Context, id uint64) bool

func (*Keeper) IncrementLastEthBlock

func (k *Keeper) IncrementLastEthBlock(ctx sdk.Context)

IncrementLastEthBlock increment last eth block

func (*Keeper) IterateSpansAndApplyFn

func (k *Keeper) IterateSpansAndApplyFn(ctx sdk.Context, f func(span hmTypes.Span) error)

IterateSpansAndApplyFn interate spans and apply the given function.

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger

func (*Keeper) SelectNextProducers

func (k *Keeper) SelectNextProducers(ctx sdk.Context, seed common.Hash) (vals []hmTypes.Validator, err error)

SelectNextProducers selects producers for next span

func (*Keeper) SetLastEthBlock

func (k *Keeper) SetLastEthBlock(ctx sdk.Context, blockNumber *big.Int)

SetLastEthBlock sets last eth block number

func (*Keeper) SetParams

func (k *Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams sets the bor module's parameters.

func (*Keeper) UpdateLastSpan

func (k *Keeper) UpdateLastSpan(ctx sdk.Context, id uint64)

UpdateLastSpan updates the last span start block

Directories

Path Synopsis
client
cli

Jump to

Keyboard shortcuts

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