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

Function updateState

state/execution.go:403–466  ·  view source on GitHub ↗

updateState returns a new State updated according to the header and responses.

(
	state State,
	blockID types.BlockID,
	header *types.Header,
	abciResponses *tmstate.ABCIResponses,
	validatorUpdates []*types.Validator,
)

Source from the content-addressed store, hash-verified

401
402// updateState returns a new State updated according to the header and responses.
403func updateState(
404 state State,
405 blockID types.BlockID,
406 header *types.Header,
407 abciResponses *tmstate.ABCIResponses,
408 validatorUpdates []*types.Validator,
409) (State, error) {
410
411 // Copy the valset so we can apply changes from EndBlock
412 // and update s.LastValidators and s.Validators.
413 nValSet := state.NextValidators.Copy()
414
415 // Update the validator set with the latest abciResponses.
416 lastHeightValsChanged := state.LastHeightValidatorsChanged
417 if len(validatorUpdates) > 0 {
418 err := nValSet.UpdateWithChangeSet(validatorUpdates)
419 if err != nil {
420 return state, fmt.Errorf("error changing validator set: %v", err)
421 }
422 // Change results from this height but only applies to the next next height.
423 lastHeightValsChanged = header.Height + 1 + 1
424 }
425
426 // Update validator proposer priority and set state variables.
427 nValSet.IncrementProposerPriority(1)
428
429 // Update the params with the latest abciResponses.
430 nextParams := state.ConsensusParams
431 lastHeightParamsChanged := state.LastHeightConsensusParamsChanged
432 if abciResponses.EndBlock.ConsensusParamUpdates != nil {
433 // NOTE: must not mutate s.ConsensusParams
434 nextParams = types.UpdateConsensusParams(state.ConsensusParams, abciResponses.EndBlock.ConsensusParamUpdates)
435 err := types.ValidateConsensusParams(nextParams)
436 if err != nil {
437 return state, fmt.Errorf("error updating consensus params: %v", err)
438 }
439
440 state.Version.Consensus.App = nextParams.Version.AppVersion
441
442 // Change results from this height but only applies to the next height.
443 lastHeightParamsChanged = header.Height + 1
444 }
445
446 nextVersion := state.Version
447
448 // NOTE: the AppHash has not been populated.
449 // It will be filled on state.Save.
450 return State{
451 Version: nextVersion,
452 ChainID: state.ChainID,
453 InitialHeight: state.InitialHeight,
454 LastBlockHeight: header.Height,
455 LastBlockID: blockID,
456 LastBlockTime: header.Time,
457 NextValidators: nValSet,
458 Validators: state.NextValidators.Copy(),
459 LastValidators: state.Validators.Copy(),
460 LastHeightValidatorsChanged: lastHeightValsChanged,

Callers 2

ApplyBlockMethod · 0.85
UpdateStateFunction · 0.85

Calls 6

UpdateConsensusParamsFunction · 0.92
ValidateConsensusParamsFunction · 0.92
ABCIResponsesResultsHashFunction · 0.85
UpdateWithChangeSetMethod · 0.80
CopyMethod · 0.65

Tested by 1

UpdateStateFunction · 0.68