app

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const MaxTxsPerBlock = 10

MaxTxsPerBlock is the maximum number of txs by a single sender per block.

Variables

This section is empty.

Functions

func SortValidators

func SortValidators(validators []abcitypes.ValidatorUpdate)

SortValidators sorts a slice of ValidatorUpdates in a determistic way suitable for updating the validators in tendermint.

Types

type Accusation

type Accusation = shutterevents.Accusation

func ParseAccusationMsg

func ParseAccusationMsg(msg *shmsg.Accusation, sender common.Address) (*Accusation, error)

ParseAccusationMsg converts a shmsg.AccusationMsg to an app.AccusationMsg.

type Apology

type Apology = shutterevents.Apology

func ParseApologyMsg

func ParseApologyMsg(msg *shmsg.Apology, sender common.Address) (*Apology, error)

ParseApologyMsg converts a shmsg.ApologyMsg to an app.ApologyMsg.

type BatchConfig

type BatchConfig = shutterevents.BatchConfig

type BatchState

type BatchState struct {
	BatchIndex           uint64
	Config               *BatchConfig
	DecryptionSignatures []DecryptionSignature
}

BatchState is used to manage the key generation process for a certain batch.

func (*BatchState) AddDecryptionSignature

func (bs *BatchState) AddDecryptionSignature(ds DecryptionSignature) error

AddDecryptionSignature adds a decryption signature to the batch.

type CheckTxState

type CheckTxState struct {
	Members      map[common.Address]bool
	TxCounts     map[common.Address]int
	NonceTracker *NonceTracker
}

CheckTxState is a part of the state used by CheckTx calls that is reset at every commit.

func NewCheckTxState

func NewCheckTxState() *CheckTxState

NewCheckTxState returns a new check tx state.

func (*CheckTxState) AddTx

func (s *CheckTxState) AddTx(sender common.Address, msg *shmsg.MessageWithNonce) bool

AddTx checks if a tx can be added and updates the internal state accordingly. Returns true if the sender is a member (or the member set is empty) and has not exceeded their tx limit yet.

func (*CheckTxState) Reset

func (s *CheckTxState) Reset()

Reset should be called at every block commit so that all nodes get the same value no matter their view on the network.

func (*CheckTxState) SetMembers

func (s *CheckTxState) SetMembers(members []common.Address)

SetMembers sets the member set allowed to send txs. Duplicate addresses are ignored.

type ConfigVoting

type ConfigVoting struct {
	Voting
	Candidates []BatchConfig
}

ConfigVoting is used to let the keypers vote on new BatchConfigs to be added Each keyper can vote exactly once.

func NewConfigVoting

func NewConfigVoting() ConfigVoting

NewConfigVoting creates a ConfigVoting struct.

func (*ConfigVoting) AddVote

func (cfgv *ConfigVoting) AddVote(sender common.Address, batchConfig BatchConfig) error

AddVote adds a vote from the given sender for the given batchConfig. It returns an error if the sender tries to vote twice.

func (*ConfigVoting) Outcome

func (cfgv *ConfigVoting) Outcome(numRequiredVotes int) (BatchConfig, bool)

Outcome checks if one of the candidates has more than numRequiredVotes.

type DKGInstance

type DKGInstance struct {
	Config BatchConfig
	Eon    uint64

	PolyEvalsSeen       map[SenderReceiverPair]struct{}
	PolyCommitmentsSeen map[common.Address]struct{}
	AccusationsSeen     map[common.Address]struct{}
	ApologiesSeen       map[common.Address]struct{}
}

DKGInstance manages the state of one eon key generation instance.

func NewDKGInstance

func NewDKGInstance(config BatchConfig, eon uint64) DKGInstance

NewDKGInstance creates a new DKGInstance.

func (*DKGInstance) RegisterAccusationMsg

func (dkg *DKGInstance) RegisterAccusationMsg(msg Accusation) error

RegisterAccusationMsg adds an accusation message to the instance.

func (*DKGInstance) RegisterApologyMsg

func (dkg *DKGInstance) RegisterApologyMsg(msg Apology) error

RegisterApologyMsg adds an apology message to the instance.

func (*DKGInstance) RegisterPolyCommitmentMsg

func (dkg *DKGInstance) RegisterPolyCommitmentMsg(msg PolyCommitment) error

RegisterPolyCommitmentMsg adds a polynomial commitment message to the instance.

func (*DKGInstance) RegisterPolyEvalMsg

func (dkg *DKGInstance) RegisterPolyEvalMsg(msg PolyEval) error

RegisterPolyEvalMsg adds a polynomial evaluation message to the instance. It makes sure the message meets the basic requirements, i.e. the sender and receivers are keypers and we do not send multiple messages from one sender to one receiver.

type DecryptionSignature

type DecryptionSignature struct {
	Sender    common.Address
	Signature []byte
}

DecryptionSignature stores the decryption key signature created by one of the keypers.

type EonStartVoting

type EonStartVoting struct {
	Voting
	Candidates []uint64
}

EonStartVoting is used to vote on the batch index at which the next eon should be started.

func NewEonStartVoting

func NewEonStartVoting() *EonStartVoting

NewEonStartVoting creates a new EonStartVoting struct.

func (*EonStartVoting) AddVote

func (v *EonStartVoting) AddVote(sender common.Address, batchIndex uint64)

AddVote adds or updates a vote for a certain start batch index.

func (*EonStartVoting) Outcome

func (v *EonStartVoting) Outcome(numRequiredVotes int) (uint64, bool)

Outcome checks if a start batch index has a majority and if so returns it.

type EpochSecretKeyShare

type EpochSecretKeyShare = shutterevents.EpochSecretKeyShare

func ParseEpochSecretKeyShareMsg

func ParseEpochSecretKeyShareMsg(msg *shmsg.EpochSecretKeyShare, sender common.Address) (*EpochSecretKeyShare, error)

ParseEpochSecretKeyShareMsg converts a shmsg.EpochSecretKeyShareMsg to an app.EpochSecretShareMsg.

type GenesisAppState

type GenesisAppState struct {
	Keypers   []common.MixedcaseAddress `json:"keypers"`
	Threshold uint64                    `json:"threshold"`
}

GenesisAppState is used to hold the initial list of keypers, who will bootstrap the system by providing the first real BatchConfig to be used. We use common.MixedcaseAddress to hold the list of keypers as that one serializes as checksum address.

func NewGenesisAppState

func NewGenesisAppState(keypers []common.Address, threshold int) GenesisAppState

func (*GenesisAppState) GetKeypers

func (appState *GenesisAppState) GetKeypers() []common.Address

GetKeypers returns the keypers defined in the GenesisAppState.

type NonceTracker

type NonceTracker struct {
	RandomNonces map[common.Address]map[uint64]bool
}

NonceTracker tracks which nonces have been used and which have not.

func NewNonceTracker

func NewNonceTracker() *NonceTracker

NewNonceTracker creates a new NonceTracker.

func (*NonceTracker) Add

func (t *NonceTracker) Add(sender common.Address, randomNonce uint64)

Add adds the given nonce if it hasn't already.

func (*NonceTracker) Check

func (t *NonceTracker) Check(sender common.Address, randomNonce uint64) bool

Check returns true if the given nonce is free and false if it has been added already.

type PolyCommitment

type PolyCommitment = shutterevents.PolyCommitment

func ParsePolyCommitmentMsg

func ParsePolyCommitmentMsg(msg *shmsg.PolyCommitment, sender common.Address) (*PolyCommitment, error)

ParsePolyCommitmentMsg converts a shmsg.PolyCommitmentMsg to an app.PolyCommitmentMsg.

type PolyEval

type PolyEval = shutterevents.PolyEval

func ParsePolyEvalMsg

func ParsePolyEvalMsg(msg *shmsg.PolyEval, sender common.Address) (*PolyEval, error)

ParsePolyEvalMsg converts a shmsg.PolyEvalMsg to an app.PolyEvalMsg.

type Powermap

type Powermap map[ValidatorPubkey]int64

Powermap maps a ValidatorPubkey to the validators voting power.

func DiffPowermaps

func DiffPowermaps(oldpm, newpm Powermap) Powermap

DiffPowermaps computes the diff to be applied by tendermint to change the old validators into the new validators.

func MakePowermap

func MakePowermap(validators []abcitypes.ValidatorUpdate) (Powermap, error)

MakePowermap creates a new Powermap with voting powers as specified in validators.

func (Powermap) ValidatorUpdates

func (pm Powermap) ValidatorUpdates() []abcitypes.ValidatorUpdate

ValidatorUpdates computes a deterministic slice of ValidatorUpdate structs.

type SenderReceiverPair

type SenderReceiverPair struct {
	Sender, Receiver common.Address
}

type ShutterApp

type ShutterApp struct {
	Configs         []*BatchConfig
	BatchStates     map[uint64]BatchState
	DKGMap          map[uint64]*DKGInstance
	ConfigVoting    ConfigVoting
	EonStartVotings map[uint64]*EonStartVoting
	Gobpath         string
	LastSaved       time.Time
	LastBlockHeight int64
	Identities      map[common.Address]ValidatorPubkey
	StartedVotes    map[common.Address]struct{}
	Validators      Powermap
	EONCounter      uint64
	DevMode         bool
	CheckTxState    *CheckTxState
	NonceTracker    *NonceTracker
	ChainID         string
}

ShutterApp holds our data structures used for the tendermint app.

func LoadShutterAppFromFile

func LoadShutterAppFromFile(gobpath string) (ShutterApp, error)

LoadShutterAppFromFile loads a shutter app from a file.

func NewShutterApp

func NewShutterApp() *ShutterApp

NewShutterApp creates a new ShutterApp.

func (*ShutterApp) CheckTx

CheckTx checks if a transaction is valid. If return Code != 0, it will be rejected from the mempool and hence not broadcasted to other peers and not included in a proposal block.

func (*ShutterApp) Commit

func (app *ShutterApp) Commit() abcitypes.ResponseCommit

func (*ShutterApp) CurrentValidators

func (app *ShutterApp) CurrentValidators() Powermap

CurrentValidators returns a powermap of current validators.

func (*ShutterApp) DeliverTx

func (*ShutterApp) EndBlock

func (*ShutterApp) Info

Info should return the latest committed state of the app. On startup, tendermint calls the Info method and will replay blocks that are not yet committed. See https://github.com/tendermint/spec/blob/master/spec/abci/apps.md#crash-recovery

func (*ShutterApp) InitChain

BlockExecution

The first time a new blockchain is started, Tendermint calls InitChain. From then on, the following sequence of methods is executed for each block:

BeginBlock, [DeliverTx], EndBlock, Commit

where one DeliverTx is called for each transaction in the block. The result is an updated application state. Cryptographic commitments to the results of DeliverTx, EndBlock, and Commit are included in the header of the next block.

func (*ShutterApp) LastConfig

func (app *ShutterApp) LastConfig() *BatchConfig

LastConfig returns the config with the highest known index.

func (*ShutterApp) PersistToDisk

func (app *ShutterApp) PersistToDisk() error

persistToDisk stores the ShutterApp on disk. This method first writes to a temporary file and renames the file later. Most probably this will not work on windows!

func (*ShutterApp) Query

func (*ShutterApp) ShouldStartDKG

func (app *ShutterApp) ShouldStartDKG(config BatchConfig) bool

ShouldStartDKG checks if the DKG should be started, because the threshold or the list of keypers changed.

func (*ShutterApp) StartDKG

func (app *ShutterApp) StartDKG(config BatchConfig) *DKGInstance

type ValidatorPubkey

type ValidatorPubkey struct {
	Ed25519pubkey string
}

ValidatorPubkey holds the raw 32 byte ed25519 public key to be used as tendermint validator key We use this is a map key, so don't use a byte slice.

var (
	// PersistMinDuration is the minimum duration between two calls to persistToDisk
	// TODO we should probably increase the default here and we should have a way to collect
	// garbage to keep the persisted state small enough.
	// The variable is declared here, because we do not want to persist it as part of the
	// application. The same could be said about the Gobpath field though, which we persist as
	// part of the application.
	// If we set this to zero, the state will get saved on every call to Commit.
	PersistMinDuration time.Duration = 30 * time.Second

	// NonExistentValidator is an artificial key used to replace the voting power of validators
	// that haven't sent their CheckIn message yet.
	NonExistentValidator ValidatorPubkey
)

func NewValidatorPubkey

func NewValidatorPubkey(pubkey []byte) (ValidatorPubkey, error)

NewValidatorPubkey creates a new ValidatorPubkey from a 32 byte ed25519 raw pubkey. See https://docs.tendermint.com/master/spec/abci/apps.html#validator-updates for more information

func (ValidatorPubkey) String

func (vp ValidatorPubkey) String() string

type Voting

type Voting struct {
	Votes map[common.Address]int
}

Voting is a struct storing votes for arbitrary indices.

func NewVoting

func NewVoting() Voting

NewVoting creates a new Voting struct.

func (*Voting) AddVoteForIndex

func (v *Voting) AddVoteForIndex(sender common.Address, index int)

AddVoteForIndex adds a vote from the given sender for the given index.

func (*Voting) OutcomeIndex

func (v *Voting) OutcomeIndex(numRequiredVotes int) (int, bool)

OutcomeIndex checks if one of the candidate indices has more than numRequiredVotes.

Jump to

Keyboard shortcuts

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