MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / MakeBlock

Method MakeBlock

state/state.go:234–262  ·  view source on GitHub ↗

------------------------------------------------------------------------ Create a block from the latest state MakeBlock builds a block from the current state with the given txs, commit, and evidence. Note it also takes a proposerAddress because the state does not track rounds, and hence does not kno

(
	height int64,
	txs []types.Tx,
	commit *types.Commit,
	evidence []types.Evidence,
	proposerAddress []byte,
)

Source from the content-addressed store, hash-verified

232// and evidence. Note it also takes a proposerAddress because the state does not
233// track rounds, and hence does not know the correct proposer. TODO: fix this!
234func (state State) MakeBlock(
235 height int64,
236 txs []types.Tx,
237 commit *types.Commit,
238 evidence []types.Evidence,
239 proposerAddress []byte,
240) (*types.Block, *types.PartSet) {
241 // Build base block with block data.
242 block := types.MakeBlock(height, txs, commit, evidence)
243
244 // Set time.
245 var timestamp time.Time
246 if height == state.InitialHeight {
247 timestamp = state.LastBlockTime // genesis time
248 } else {
249 timestamp = MedianTime(commit, state.LastValidators)
250 }
251
252 // Fill rest of header with state data.
253 block.Header.Populate(
254 state.Version.Consensus, state.ChainID,
255 timestamp, state.LastBlockID,
256 state.Validators.Hash(), state.NextValidators.Hash(),
257 types.HashConsensusParams(state.ConsensusParams), state.AppHash, state.LastResultsHash,
258 proposerAddress,
259 )
260
261 return block, block.MakePartSet(types.BlockPartSizeBytes)
262}
263
264// MedianTime computes a median time for a given Commit (based on Timestamp field of votes messages) and the
265// corresponding validator set. The computed time is always between timestamps of

Callers 13

makeAndApplyGoodBlockFunction · 0.80
makeBlockFunction · 0.80
TestValidateBlockHeaderFunction · 0.80
TestValidateBlockCommitFunction · 0.80
TestBeginBlockValidatorsFunction · 0.80
CreateProposalBlockMethod · 0.80
makeBlockFunction · 0.80
makeBlockFunction · 0.80
makeBlockFunction · 0.80
makeBlockFunction · 0.80
initializeBlockStoreFunction · 0.80

Calls 6

MakeBlockFunction · 0.92
HashConsensusParamsFunction · 0.92
MedianTimeFunction · 0.85
PopulateMethod · 0.80
MakePartSetMethod · 0.80
HashMethod · 0.65

Tested by 12

makeAndApplyGoodBlockFunction · 0.64
makeBlockFunction · 0.64
TestValidateBlockHeaderFunction · 0.64
TestValidateBlockCommitFunction · 0.64
TestBeginBlockValidatorsFunction · 0.64
makeBlockFunction · 0.64
makeBlockFunction · 0.64
makeBlockFunction · 0.64
makeBlockFunction · 0.64
initializeBlockStoreFunction · 0.64
makeBlockFunction · 0.64