-
Notifications
You must be signed in to change notification settings - Fork 324
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
[facotry] add factoryWithHeight for archive mode #4474
base: master
Are you sure you want to change the base?
Conversation
d690491
to
fbadbad
Compare
ArchiveStateSimulator interface { | ||
StateReader | ||
SimulateExecution(context.Context, address.Address, action.Envelope, ...SimulateOption) ([]byte, *action.Receipt, error) | ||
ReadContractStorage(context.Context, address.Address, []byte) ([]byte, error) |
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.
these 2 are needed for archive-node API
} | ||
return state.NewIterator(keys, values) | ||
} | ||
|
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.
move to factoryWithHeight
state/factory/factory_withheight.go
Outdated
sf.mutex.RLock() | ||
defer sf.mutex.RUnlock() |
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 does it share the same mutex with factory?
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.
yeah, I think reading on archive state can be lock-free
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.
updated in latest commit
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.
SimulateExecution
and ReadContractStorage
also need re-implement, they are not currently based on the specified height, but rather on the latest height
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.
ok just added, was thinking to add it later in API PR
timer := sf.timerFactory.NewTimer("Commit") | ||
sf.mutex.Unlock() |
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.
when reviewing the usage of sf.mutex
, found it's not really needed here
Quality Gate failedFailed conditions |
cfg, err := processOptions(opts...) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if cfg.Keys != nil { | ||
return 0, errors.Wrap(ErrNotSupported, "Read state with keys option has not been implemented yet") | ||
} | ||
if sf.height > sf.currentChainHeight { | ||
return 0, errors.Errorf("query height %d is higher than tip height %d", sf.height, sf.currentChainHeight) | ||
} |
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.
move the check to AtHeight()
return sf.height, sf.stateAtHeight(sf.height, cfg.Namespace, cfg.Key, s) | ||
} | ||
|
||
func (sf *factoryWithHeight) stateAtHeight(height uint64, ns string, key []byte, s interface{}) error { | ||
if !sf.saveHistory { | ||
return ErrNoArchiveData | ||
} |
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.
the check is already there in AtHeight()
defer sf.mutex.RUnlock() | ||
if sf.height > sf.currentChainHeight { | ||
return 0, nil, errors.Errorf("query height %d is higher than tip height %d", sf.height, sf.currentChainHeight) | ||
} |
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.
move the check to AtHeight()
Description
make the Factory interface more natural to support archive mode
Fixes #(issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: