Skip to content
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

Drop explicit calls to chain.GetTx from txs execution paths #2431

Closed
wants to merge 66 commits into from

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Dec 6, 2023

Why this should be merged

MerkleDB is likely to require dropping the use of Chain.GetTx in txs execution in favour of smaller, more specific data, whose lifetime is bounded as stakers objects' one. That is to say object that can be deleted once staker is removed, unlike txs which are currently stored indefinitely on disk.
This PR is a step into that direction: without removing Chain.GetTx, we add a couple of method to state.Chain interface. What we achieve in this PR is that chain.GetTx won't be explicitly called in txs execution, outside of the state package.
What we gain in this way is freedom for a merkleDB based P-chain to avoid storing txs into the merkleDB section, since they won't be needed to verify transactions.
In this PR we still use chain.GetTx under the hood, so that we avoid storing extra data to db and requiring a db migration.

The increase in LOC is mostly due to mock implementation of the new methods

How this works

This PR adds

  • GetChainSubnet(chainID ids.ID) (ids.ID, error)
  • GetStakerRewardAttributes(stakerID ids.ID) (*StakerRewardAttributes, error)

to state.Chain.
This PR does not:

  1. change data layout on db (no extra data added, no data removed)
  2. introduce a DeleteStakerRewardAttributes (similar to DeleteStaker, to bound cold attribute lifetime), yet, since stakers cold attribute are not store independently from txs. But a P-chain merkleDB could!

How this was tested

CI

@abi87 abi87 self-assigned this Dec 6, 2023
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
@@ -96,6 +96,7 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) {
StartTime: utx.StartTime(),
NextTime: chainTime,
EndTime: chainTime,
Priority: utx.CurrentPriority(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed for rewritten RewardStaker to pass

Comment on lines -93 to -81
type stakerAttributes struct {
shares uint32
rewardsOwner fx.Owner
validationRewardsOwner fx.Owner
delegationRewardsOwner fx.Owner
proofOfPossession *signer.ProofOfPossession
Copy link
Contributor Author

@abi87 abi87 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR promotes this struct to state package, renaming it StakerRewardAttributes

"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)

func getStakerColdAttributes(chain Chain, stakerID ids.ID) (*StakerColdAttributes, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods are just to avoid code duplication across state.State and state.Diff.
MerkleDB implementation is likely to have different implementation and not require these methods

@abi87 abi87 marked this pull request as ready for review December 6, 2023 12:51
@abi87 abi87 changed the title [DRAFT] Pchain merkle db: Drop GetTx from execution paths Drop explicit calls to chain.GetTx from txs execution paths Dec 6, 2023
vms/platformvm/service.go Outdated Show resolved Hide resolved
@abi87 abi87 changed the base branch from dev to master January 24, 2024 11:38
abi87 added 25 commits January 26, 2024 16:10
Copy link

This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen label will cause this PR to ignore lifecycle events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

P-chain state sync
4 participants