github.com/algorand/go-algorand-sdk@v1.24.0/types/block.go (about) 1 package types 2 3 type ( 4 // BlockHash represents the hash of a block 5 BlockHash Digest 6 7 // A BlockHeader represents the metadata and commitments to the state of a Block. 8 // The Algorand Ledger may be defined minimally as a cryptographically authenticated series of BlockHeader objects. 9 BlockHeader struct { 10 _struct struct{} `codec:",omitempty,omitemptyarray"` 11 12 Round Round `codec:"rnd"` 13 14 // The hash of the previous block 15 Branch BlockHash `codec:"prev"` 16 17 // Sortition seed 18 Seed [32]byte `codec:"seed"` 19 20 TxnCommitments 21 22 // TimeStamp in seconds since epoch 23 TimeStamp int64 `codec:"ts"` 24 25 // Genesis ID to which this block belongs. 26 GenesisID string `codec:"gen"` 27 28 // Genesis hash to which this block belongs. 29 GenesisHash Digest `codec:"gh"` 30 31 // Rewards. 32 // 33 // When a block is applied, some amount of rewards are accrued to 34 // every account with AccountData.Status=/=NotParticipating. The 35 // amount is (thisBlock.RewardsLevel-prevBlock.RewardsLevel) of 36 // MicroAlgos for every whole config.Protocol.RewardUnit of MicroAlgos in 37 // that account's AccountData.MicroAlgos. 38 // 39 // Rewards are not compounded (i.e., not added to AccountData.MicroAlgos) 40 // until some other transaction is executed on that account. 41 // 42 // Not compounding rewards allows us to precisely know how many algos 43 // of rewards will be distributed without having to examine every 44 // account to determine if it should get one more algo of rewards 45 // because compounding formed another whole config.Protocol.RewardUnit 46 // of algos. 47 RewardsState 48 49 // Consensus protocol versioning. 50 // 51 // Each block is associated with a version of the consensus protocol, 52 // stored under UpgradeState.CurrentProtocol. The protocol version 53 // for a block can be determined without having to first decode the 54 // block and its CurrentProtocol field, and this field is present for 55 // convenience and explicitness. Block.Valid() checks that this field 56 // correctly matches the expected protocol version. 57 // 58 // Each block is associated with at most one active upgrade proposal 59 // (a new version of the protocol). An upgrade proposal can be made 60 // by a block proposer, as long as no other upgrade proposal is active. 61 // The upgrade proposal lasts for many rounds (UpgradeVoteRounds), and 62 // in each round, that round's block proposer votes to support (or not) 63 // the proposed upgrade. 64 // 65 // If enough votes are collected, the proposal is approved, and will 66 // definitely take effect. The proposal lingers for some number of 67 // rounds to give clients a chance to notify users about an approved 68 // upgrade, if the client doesn't support it, so the user has a chance 69 // to download updated client software. 70 // 71 // Block proposers influence this upgrade machinery through two fields 72 // in UpgradeVote: UpgradePropose, which proposes an upgrade to a new 73 // protocol, and UpgradeApprove, which signals approval of the current 74 // proposal. 75 // 76 // Once a block proposer determines its UpgradeVote, then UpdateState 77 // is updated deterministically based on the previous UpdateState and 78 // the new block's UpgradeVote. 79 UpgradeState 80 UpgradeVote 81 82 // TxnCounter counts the number of transactions committed in the 83 // ledger, from the time at which support for this feature was 84 // introduced. 85 // 86 // Specifically, TxnCounter is the number of the next transaction 87 // that will be committed after this block. It is 0 when no 88 // transactions have ever been committed (since TxnCounter 89 // started being supported). 90 TxnCounter uint64 `codec:"tc"` 91 92 // StateProofTracking tracks the status of the state proofs, potentially 93 // for multiple types of ASPs (Algorand's State Proofs). 94 //msgp:sort protocol.StateProofType protocol.SortStateProofType 95 StateProofTracking map[StateProofType]StateProofTrackingData `codec:"spt,allocbound=NumStateProofTypes"` 96 97 // ParticipationUpdates contains the information needed to mark 98 // certain accounts offline because their participation keys expired 99 ParticipationUpdates 100 } 101 102 // TxnCommitments represents the commitments computed from the transactions in the block. 103 // It contains multiple commitments based on different algorithms and hash functions, to support different use cases. 104 TxnCommitments struct { 105 _struct struct{} `codec:",omitempty,omitemptyarray"` 106 // Root of transaction merkle tree using SHA512_256 hash function. 107 // This commitment is computed based on the PaysetCommit type specified in the block's consensus protocol. 108 NativeSha512_256Commitment Digest `codec:"txn"` 109 110 // Root of transaction vector commitment merkle tree using SHA256 hash function 111 Sha256Commitment Digest `codec:"txn256"` 112 } 113 114 // ParticipationUpdates represents participation account data that 115 // needs to be checked/acted on by the network 116 ParticipationUpdates struct { 117 _struct struct{} `codec:",omitempty,omitemptyarray"` 118 119 // ExpiredParticipationAccounts contains a list of online accounts 120 // that needs to be converted to offline since their 121 // participation key expired. 122 ExpiredParticipationAccounts []Address `codec:"partupdrmv"` 123 } 124 125 // RewardsState represents the global parameters controlling the rate 126 // at which accounts accrue rewards. 127 RewardsState struct { 128 _struct struct{} `codec:",omitempty,omitemptyarray"` 129 130 // The FeeSink accepts transaction fees. It can only spend to 131 // the incentive pool. 132 FeeSink Address `codec:"fees"` 133 134 // The RewardsPool accepts periodic injections from the 135 // FeeSink and continually redistributes them to adresses as 136 // rewards. 137 RewardsPool Address `codec:"rwd"` 138 139 // RewardsLevel specifies how many rewards, in MicroAlgos, 140 // have been distributed to each config.Protocol.RewardUnit 141 // of MicroAlgos since genesis. 142 RewardsLevel uint64 `codec:"earn"` 143 144 // The number of new MicroAlgos added to the participation stake from rewards at the next round. 145 RewardsRate uint64 `codec:"rate"` 146 147 // The number of leftover MicroAlgos after the distribution of RewardsRate/rewardUnits 148 // MicroAlgos for every reward unit in the next round. 149 RewardsResidue uint64 `codec:"frac"` 150 151 // The round at which the RewardsRate will be recalculated. 152 RewardsRecalculationRound Round `codec:"rwcalr"` 153 } 154 155 // UpgradeVote represents the vote of the block proposer with 156 // respect to protocol upgrades. 157 UpgradeVote struct { 158 _struct struct{} `codec:",omitempty,omitemptyarray"` 159 160 // UpgradePropose indicates a proposed upgrade 161 UpgradePropose string `codec:"upgradeprop"` 162 163 // UpgradeDelay indicates the time between acceptance and execution 164 UpgradeDelay Round `codec:"upgradedelay"` 165 166 // UpgradeApprove indicates a yes vote for the current proposal 167 UpgradeApprove bool `codec:"upgradeyes"` 168 } 169 170 // UpgradeState tracks the protocol upgrade state machine. It is, 171 // strictly speaking, computable from the history of all UpgradeVotes 172 // but we keep it in the block for explicitness and convenience 173 // (instead of materializing it separately, like balances). 174 //msgp:ignore UpgradeState 175 UpgradeState struct { 176 CurrentProtocol string `codec:"proto"` 177 NextProtocol string `codec:"nextproto"` 178 NextProtocolApprovals uint64 `codec:"nextyes"` 179 NextProtocolVoteBefore Round `codec:"nextbefore"` 180 NextProtocolSwitchOn Round `codec:"nextswitch"` 181 } 182 183 // StateProofTrackingData tracks the status of state proofs. 184 StateProofTrackingData struct { 185 _struct struct{} `codec:",omitempty,omitemptyarray"` 186 187 // StateProofVotersCommitment is the root of a vector commitment containing the 188 // online accounts that will help sign a state proof. The 189 // VC root, and the state proof, happen on blocks that 190 // are a multiple of ConsensusParams.StateProofRounds. For blocks 191 // that are not a multiple of ConsensusParams.StateProofRounds, 192 // this value is zero. 193 StateProofVotersCommitment GenericDigest `codec:"v"` 194 195 // StateProofOnlineTotalWeight is the total number of microalgos held by the online accounts 196 // during the StateProof round (or zero, if the merkle root is zero - no commitment for StateProof voters). 197 // This is intended for computing the threshold of votes to expect from StateProofVotersCommitment. 198 StateProofOnlineTotalWeight MicroAlgos `codec:"t"` 199 200 // StateProofNextRound is the next round for which we will accept 201 // a StateProof transaction. 202 StateProofNextRound Round `codec:"n"` 203 } 204 205 // A Block contains the Payset and metadata corresponding to a given Round. 206 Block struct { 207 BlockHeader 208 Payset Payset `codec:"txns"` 209 } 210 211 // A Payset represents a common, unforgeable, consistent, ordered set of SignedTxn objects. 212 //msgp:allocbound Payset 100000 213 Payset []SignedTxnInBlock 214 215 // SignedTxnInBlock is how a signed transaction is encoded in a block. 216 SignedTxnInBlock struct { 217 _struct struct{} `codec:",omitempty,omitemptyarray"` 218 219 SignedTxnWithAD 220 221 HasGenesisID bool `codec:"hgi"` 222 HasGenesisHash bool `codec:"hgh"` 223 } 224 // SignedTxnWithAD is a (decoded) SignedTxn with associated ApplyData 225 SignedTxnWithAD struct { 226 _struct struct{} `codec:",omitempty,omitemptyarray"` 227 228 SignedTxn 229 ApplyData 230 } 231 232 // ApplyData contains information about the transaction's execution. 233 ApplyData struct { 234 _struct struct{} `codec:",omitempty,omitemptyarray"` 235 236 // Closing amount for transaction. 237 ClosingAmount MicroAlgos `codec:"ca"` 238 239 // Closing amount for asset transaction. 240 AssetClosingAmount uint64 `codec:"aca"` 241 242 // Rewards applied to the Sender, Receiver, and CloseRemainderTo accounts. 243 SenderRewards MicroAlgos `codec:"rs"` 244 ReceiverRewards MicroAlgos `codec:"rr"` 245 CloseRewards MicroAlgos `codec:"rc"` 246 EvalDelta EvalDelta `codec:"dt"` 247 248 ConfigAsset uint64 `codec:"caid"` 249 ApplicationID uint64 `codec:"apid"` 250 } 251 ) 252 253 type EvalDelta struct { 254 _struct struct{} `codec:",omitempty,omitemptyarray"` 255 256 GlobalDelta StateDelta `codec:"gd"` 257 258 // When decoding EvalDeltas, the integer key represents an offset into 259 // [txn.Sender, txn.Accounts[0], txn.Accounts[1], ...] 260 LocalDeltas map[uint64]StateDelta `codec:"ld,allocbound=config.MaxEvalDeltaAccounts"` 261 262 Logs []string `codec:"lg"` 263 264 InnerTxns []SignedTxnWithAD `codec:"itx"` 265 } 266 267 // StateDelta is a map from key/value store keys to ValueDeltas, indicating 268 // what should happen for that key 269 //msgp:allocbound StateDelta config.MaxStateDeltaKeys 270 type StateDelta map[string]ValueDelta 271 272 // ValueDelta links a DeltaAction with a value to be set 273 type ValueDelta struct { 274 _struct struct{} `codec:",omitempty,omitemptyarray"` 275 276 Action DeltaAction `codec:"at"` 277 Bytes string `codec:"bs"` 278 Uint uint64 `codec:"ui"` 279 } 280 281 // DeltaAction is an enum of actions that may be performed when applying a 282 // delta to a TEAL key/value store 283 type DeltaAction uint64 284 285 const ( 286 // SetBytesAction indicates that a TEAL byte slice should be stored at a key 287 SetBytesAction DeltaAction = 1 288 289 // SetUintAction indicates that a Uint should be stored at a key 290 SetUintAction DeltaAction = 2 291 292 // DeleteAction indicates that the value for a particular key should be deleted 293 DeleteAction DeltaAction = 3 294 )