Documentation ¶
Index ¶
- func SignedTxnGroupsFlatten(txgroups [][]transactions.SignedTxn) (res []transactions.SignedTxn)
- func SignedTxnsToGroups(txns []transactions.SignedTxn) (res [][]transactions.SignedTxn)
- type Block
- func (block Block) ConsensusProtocol() config.ConsensusParams
- func (block Block) ContentsMatchHeader() bool
- func (block Block) DecodePaysetFlat() ([]transactions.SignedTxnWithAD, error)
- func (block Block) DecodePaysetGroups() ([][]transactions.SignedTxnWithAD, error)
- func (block Block) Digest() crypto.Digest
- func (block Block) GenesisHash() crypto.Digest
- func (block Block) GenesisID() string
- func (block Block) Round() basics.Round
- func (block *Block) Seed() committee.Seed
- func (b Block) String() string
- func (block Block) WithSeed(s committee.Seed) Block
- type BlockHash
- type BlockHeader
- func (bh BlockHeader) DecodeSignedTxn(stb transactions.SignedTxnInBlock) (transactions.SignedTxn, transactions.ApplyData, error)
- func (bh BlockHeader) EncodeSignedTxn(st transactions.SignedTxn, ad transactions.ApplyData) (transactions.SignedTxnInBlock, error)
- func (bh BlockHeader) Hash() BlockHash
- func (bh BlockHeader) NextVersionInfo() (ver protocol.ConsensusVersion, rnd basics.Round, supported bool)
- func (bh BlockHeader) PreCheck(prev BlockHeader) error
- func (bh BlockHeader) ToBeHashed() (protocol.HashID, []byte)
- type Genesis
- type GenesisAllocation
- type RewardsState
- type UpgradeState
- type UpgradeVote
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SignedTxnGroupsFlatten ¶
func SignedTxnGroupsFlatten(txgroups [][]transactions.SignedTxn) (res []transactions.SignedTxn)
SignedTxnGroupsFlatten combines all groups into a flat slice of SignedTxns.
func SignedTxnsToGroups ¶
func SignedTxnsToGroups(txns []transactions.SignedTxn) (res [][]transactions.SignedTxn)
SignedTxnsToGroups splits a slice of SignedTxns into groups.
Types ¶
type Block ¶
type Block struct { BlockHeader Payset transactions.Payset `codec:"txns"` }
A Block contains the Payset and metadata corresponding to a given Round.
func MakeBlock ¶
func MakeBlock(prev BlockHeader) Block
MakeBlock constructs a new valid block with an empty payset and an unset Seed.
func (Block) ConsensusProtocol ¶
func (block Block) ConsensusProtocol() config.ConsensusParams
ConsensusProtocol returns the consensus protocol params for a block
func (Block) ContentsMatchHeader ¶
ContentsMatchHeader checks that the TxnRoot matches what's in the header, as the header is what the block hash authenticates. If we're given an untrusted block and a known-good hash, we can't trust the block's transactions unless we validate this.
func (Block) DecodePaysetFlat ¶
func (block Block) DecodePaysetFlat() ([]transactions.SignedTxnWithAD, error)
DecodePaysetFlat decodes block.Payset using DecodeSignedTxn, and flattens groups.
func (Block) DecodePaysetGroups ¶
func (block Block) DecodePaysetGroups() ([][]transactions.SignedTxnWithAD, error)
DecodePaysetGroups decodes block.Payset using DecodeSignedTxn, and returns the transactions in groups.
func (Block) GenesisHash ¶
GenesisHash returns the genesis hash from the block header
type BlockHash ¶
BlockHash represents the hash of a block
func (BlockHash) MarshalText ¶
MarshalText returns the BlockHash string as an array of bytes
func (*BlockHash) UnmarshalText ¶
UnmarshalText initializes the BlockHash from an array of bytes.
type BlockHeader ¶
type BlockHeader struct { Round basics.Round `codec:"rnd"` // The hash of the previous block Branch BlockHash `codec:"prev"` // Sortition seed Seed committee.Seed `codec:"seed"` // TxnRoot authenticates the set of transactions appearing in the block. // More specifically, it's the root of a merkle tree whose leaves are the block's Txids. // Note that the TxnRoot does not authenticate the signatures on the transactions, only the transactions themselves. // Two blocks with the same transactions but with different signatures will have the same TxnRoot. TxnRoot crypto.Digest `codec:"txn"` // TimeStamp in seconds since epoch TimeStamp int64 `codec:"ts"` // Genesis ID to which this block belongs. GenesisID string `codec:"gen"` // Genesis hash to which this block belongs. GenesisHash crypto.Digest `codec:"gh"` // Rewards. // // When a block is applied, some amount of rewards are accrued to // every account with AccountData.Status=/=NotParticipating. The // amount is (thisBlock.RewardsLevel-prevBlock.RewardsLevel) of // MicroAlgos for every whole config.Protocol.RewardUnit of MicroAlgos in // that account's AccountData.MicroAlgos. // // Rewards are not compounded (i.e., not added to AccountData.MicroAlgos) // until some other transaction is executed on that account. // // Not compounding rewards allows us to precisely know how many algos // of rewards will be distributed without having to examine every // account to determine if it should get one more algo of rewards // because compounding formed another whole config.Protocol.RewardUnit // of algos. RewardsState // Consensus protocol versioning. // // Each block is associated with a version of the consensus protocol, // stored under UpgradeState.CurrentProtocol. The protocol version // for a block can be determined without having to first decode the // block and its CurrentProtocol field, and this field is present for // convenience and explicitness. Block.Valid() checks that this field // correctly matches the expected protocol version. // // Each block is associated with at most one active upgrade proposal // (a new version of the protocol). An upgrade proposal can be made // by a block proposer, as long as no other upgrade proposal is active. // The upgrade proposal lasts for many rounds (UpgradeVoteRounds), and // in each round, that round's block proposer votes to support (or not) // the proposed upgrade. // // If enough votes are collected, the proposal is approved, and will // definitely take effect. The proposal lingers for some number of // rounds (UpgradeWaitRounds) to give clients a chance to notify users // about an approved upgrade, if the client doesn't support it, so the // user has a chance to download updated client software. // // Block proposers influence this upgrade machinery through two fields // in UpgradeVote: UpgradePropose, which proposes an upgrade to a new // protocol, and UpgradeApprove, which signals approval of the current // proposal. // // Once a block proposer determines its UpgradeVote, then UpdateState // is updated deterministically based on the previous UpdateState and // the new block's UpgradeVote. UpgradeState UpgradeVote // TxnCounter counts the number of transactions committed in the // ledger, from the time at which support for this feature was // introduced. // // Specifically, TxnCounter is the number of the next transaction // that will be committed after this block. It is 0 when no // transactions have ever been committed (since TxnCounter // started being supported). TxnCounter uint64 `codec:"tc"` // contains filtered or unexported fields }
A BlockHeader represents the metadata and commitments to the state of a Block. The Algorand Ledger may be defined minimally as a cryptographically authenticated series of BlockHeader objects.
func (BlockHeader) DecodeSignedTxn ¶
func (bh BlockHeader) DecodeSignedTxn(stb transactions.SignedTxnInBlock) (transactions.SignedTxn, transactions.ApplyData, error)
DecodeSignedTxn converts a SignedTxnInBlock from a block to SignedTxn and its associated ApplyData.
func (BlockHeader) EncodeSignedTxn ¶
func (bh BlockHeader) EncodeSignedTxn(st transactions.SignedTxn, ad transactions.ApplyData) (transactions.SignedTxnInBlock, error)
EncodeSignedTxn converts a SignedTxn and ApplyData into a SignedTxnInBlock for that block.
func (BlockHeader) Hash ¶
func (bh BlockHeader) Hash() BlockHash
Hash returns the hash of a block header. The hash of a block is the hash of its header.
func (BlockHeader) NextVersionInfo ¶
func (bh BlockHeader) NextVersionInfo() (ver protocol.ConsensusVersion, rnd basics.Round, supported bool)
NextVersionInfo returns information about the next expected protocol version. If no upgrade is scheduled, return the current protocol.
func (BlockHeader) PreCheck ¶
func (bh BlockHeader) PreCheck(prev BlockHeader) error
PreCheck checks if the block header bh is a valid successor to the previous block's header, prev.
func (BlockHeader) ToBeHashed ¶
func (bh BlockHeader) ToBeHashed() (protocol.HashID, []byte)
ToBeHashed implements the crypto.Hashable interface
type Genesis ¶
type Genesis struct { // The SchemaID allows nodes to store data specific to a particular // universe (in case of upgrades at development or testing time), // and as an optimization to quickly check if two nodes are in // the same universe. SchemaID string `codec:"id"` // Network identifies the unique algorand network for which the ledger // is valid. // Note the Network name should not include a '-', as we generate the // GenesisID from "<Network>-<SchemaID>"; the '-' makes it easy // to distinguish between the network and schema. Network protocol.NetworkID `codec:"network"` // Proto is the consensus protocol in use at the genesis block. Proto protocol.ConsensusVersion `codec:"proto"` // Allocation determines the initial accounts and their state. Allocation []GenesisAllocation `codec:"alloc"` // RewardsPool is the address of the rewards pool. RewardsPool string `codec:"rwd"` // FeeSink is the address of the fee sink. FeeSink string `codec:"fees"` // Timestamp for the genesis block Timestamp int64 `codec:"timestamp"` // Arbitrary genesis comment string - will be excluded from file if empty Comment string `codec:"comment"` // contains filtered or unexported fields }
A Genesis object defines an Algorand "universe" -- a set of nodes that can talk to each other, agree on the ledger contents, etc. This is defined by the initial account states (GenesisAllocation), the initial consensus protocol (GenesisProto), and the schema of the ledger.
func LoadGenesisFromFile ¶
LoadGenesisFromFile attempts to load a Genesis structure from a (presumably) genesis.json file.
type GenesisAllocation ¶
type GenesisAllocation struct { Address string `codec:"addr"` Comment string `codec:"comment"` State basics.AccountData `codec:"state"` }
A GenesisAllocation object represents an allocation of algos to an address in the genesis block. Address is the checksummed short address. Comment is a note about what this address is representing, and is purely informational. State is the initial account state.
type RewardsState ¶
type RewardsState struct { // The FeeSink accepts transaction fees. It can only spend to // the incentive pool. FeeSink basics.Address `codec:"fees"` // The RewardsPool accepts periodic injections from the // FeeSink and continually redistributes them to adresses as // rewards. RewardsPool basics.Address `codec:"rwd"` // RewardsLevel specifies how many rewards, in MicroAlgos, // have been distributed to each config.Protocol.RewardUnit // of MicroAlgos since genesis. RewardsLevel uint64 `codec:"earn"` // The number of new MicroAlgos added to the participation stake from rewards at the next round. RewardsRate uint64 `codec:"rate"` // The number of leftover MicroAlgos after the distribution of RewardsRate/rewardUnits // MicroAlgos for every reward unit in the next round. RewardsResidue uint64 `codec:"frac"` // The round at which the RewardsRate will be recalculated. RewardsRecalculationRound basics.Round `codec:"rwcalr"` }
RewardsState represents the global parameters controlling the rate at which accounts accrue rewards.
func (RewardsState) NextRewardsState ¶
func (s RewardsState) NextRewardsState(nextRound basics.Round, nextProto config.ConsensusParams, incentivePoolBalance basics.MicroAlgos, totalRewardUnits uint64) (res RewardsState)
NextRewardsState computes the RewardsState of the subsequent round given the subsequent consensus parameters, along with the incentive pool balance and the total reward units in the system as of the current round.
type UpgradeState ¶
type UpgradeState struct { CurrentProtocol protocol.ConsensusVersion `codec:"proto"` NextProtocol protocol.ConsensusVersion `codec:"nextproto"` NextProtocolApprovals uint64 `codec:"nextyes"` NextProtocolVoteBefore basics.Round `codec:"nextbefore"` NextProtocolSwitchOn basics.Round `codec:"nextswitch"` }
UpgradeState tracks the protocol upgrade state machine. It is, strictly speaking, computable from the history of all UpgradeVotes but we keep it in the block for explicitness and convenience (instead of materializing it separately, like balances).
type UpgradeVote ¶
type UpgradeVote struct { // UpgradePropose indicates a proposed upgrade UpgradePropose protocol.ConsensusVersion `codec:"upgradeprop"` // UpgradeApprove indicates a yes vote for the current proposal UpgradeApprove bool `codec:"upgradeyes"` }
UpgradeVote represents the vote of the block proposer with respect to protocol upgrades.