-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(blockManager): refactor and use state as single source of truth for height #847
feat(blockManager): refactor and use state as single source of truth for height #847
Conversation
added total produced size accumolator to be used as submission trigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I've a coupel questions
- Why move the kv interfaces to store? Generally interfaces should be on consumer side, not producer side. (Return concrete types, accept interfaces)
- What is the purpose of adding the
from
param to pruning? It seems to complicate without benefit
block/gossip.go
Outdated
func (m *Manager) attemptApplyCachedBlocks() error { | ||
m.retrieverMutex.Lock() | ||
defer m.retrieverMutex.Unlock() | ||
|
||
for { | ||
expectedHeight := m.State.NextHeight() | ||
|
||
cachedBlock, blockExists := m.blockCache[expectedHeight] | ||
if !blockExists { | ||
break | ||
} | ||
if err := m.validateBlock(cachedBlock.Block, cachedBlock.Commit); err != nil { | ||
delete(m.blockCache, cachedBlock.Block.Header.Height) | ||
/// TODO: can we take an action here such as dropping the peer / reducing their reputation? | ||
return fmt.Errorf("block not valid at height %d, dropping it: err:%w", cachedBlock.Block.Header.Height, err) | ||
} | ||
|
||
err := m.applyBlock(cachedBlock.Block, cachedBlock.Commit, blockMetaData{source: gossipedBlock}) | ||
if err != nil { | ||
return fmt.Errorf("apply cached block: expected height: %d: %w", expectedHeight, err) | ||
} | ||
m.logger.Debug("applied cached block", "height", expectedHeight) | ||
|
||
delete(m.blockCache, cachedBlock.Block.Header.Height) | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this in manager.go because it's used not only in gossip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where else it is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in syncUntilTarget
you can check usages in IDE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved back
The store doesn't manage base/latest heights anymore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work! minor comments.
Validators: validatorSet, | ||
LastValidators: types.NewValidatorSet(nil), | ||
NextValidators: types.NewValidatorSet(nil), | ||
Validators: types.NewValidatorSet(nil), | ||
LastHeightValidatorsChanged: genDoc.InitialHeight, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't look like this param is being used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the validators related logic will be refactored
currently it's static and not changing at all
Validators: validatorSet, | ||
LastValidators: types.NewValidatorSet(nil), | ||
NextValidators: types.NewValidatorSet(nil), | ||
Validators: types.NewValidatorSet(nil), | ||
LastHeightValidatorsChanged: genDoc.InitialHeight, | ||
|
||
ConsensusParams: *genDoc.ConsensusParams, | ||
LastHeightConsensusParamsChanged: genDoc.InitialHeight, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't look like this param is being used
types/state.go
Outdated
|
||
// SetBase sets the base height if it is higher than the existing base height | ||
// returns OK if the value was updated successfully or did not need to be updated | ||
func (s *State) SetBase(height uint64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method not being used (though it can be used as we do set the BaseHeight in pruning.go)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrapped Height as it's atomic and being used all over
the base is only for pruning. I've removed the getter
types/state.go
Outdated
} | ||
|
||
// Base returns height of the earliest block saved in the Store. | ||
func (s *State) Base() uint64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method not being used (though it can be used as we do get the BaseHeight in pruning.go)
block/block.go
Outdated
newState.BaseHeight = m.Store.Base() | ||
|
||
_, err = m.Store.UpdateState(newState, nil) | ||
_ = m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block.Header.Height, validators) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we return the state here and ignore it vs not returning state at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll remove the state return var
block/produce.go
Outdated
} else { | ||
height := m.Store.Height() | ||
newHeight = height + 1 | ||
if !m.State.IsGenesis() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this if
will be entered basically 100% of the times thinking if it would be cleaner to have a produceGenesisBlock
and have part of the produceBlock
code reusable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored it a bit, take a look
there are conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just requested a few small refactors, including moving attemptApplyCachedBlocks() out of gossip file
// NextValSetFromResponses updates state based on the ABCIResponses. | ||
func (e *Executor) NextValSetFromResponses(state *types.State, resp *tmstate.ABCIResponses, block *types.Block) (*tmtypes.ValidatorSet, error) { | ||
// Dymint ignores any setValidator responses from the app, as it is manages the validator set based on the settlement consensus | ||
// TODO: this will be changed when supporting multiple sequencers from the hub | ||
validatorUpdates := []*tmtypes.Validator{} | ||
return state.NextValidators.Copy(), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inline this at all callsite: the resp and block aren't used, and it's a one liner returning error
if from <= 0 { | ||
return 0, fmt.Errorf("from height must be greater than 0") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a usess branch since if we try to fetch h=0 it will just continue
Line 33 in 953a9b8
continue |
@danwt I'll leave further renames to other prs |
ok fine re renames |
not planned, will be refactored quite soon anyway |
…for height (#847) Co-authored-by: danwt <[email protected]>
Main changes:
m.State.NextHeight()
instead ofStore.Height() + 1
as the expected next heightUpdateStateFromResponses
was renamed toNextValSetFromResponses
as that what it actually doesgossip.go
state.go
PR Standards
Opening a pull request should be able to meet the following requirements
Close #330
Close #634
<-- Briefly describe the content of this pull request -->
For Author:
godoc
commentsFor Reviewer:
After reviewer approval: