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

Remove X-chain UniqueTx #1662

Merged
merged 8 commits into from
Jun 28, 2023
Merged

Remove X-chain UniqueTx #1662

merged 8 commits into from
Jun 28, 2023

Conversation

StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Jun 27, 2023

Why this should be merged

UniqueTx is no longer needed since all AVM instances have been linearized.

How this works

  • Removes persistence of transactions during ParseTx.
  • Removes persistence of statuses.
  • Removes usage of the de-duplicator cache.
  • Only returns accepted transactions from the state layer.

How this was tested

  • CI
  • Fuji full sync
  • Mainnet full sync

@StephenButtolph StephenButtolph self-assigned this Jun 27, 2023
@StephenButtolph StephenButtolph added vm This involves virtual machines cleanup Code quality improvement labels Jun 27, 2023
@StephenButtolph StephenButtolph added this to the v1.10.4 milestone Jun 27, 2023
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation is now used for all X-chain state.

vms/avm/tx.go Outdated
tx.vm.state.AddTx(tx.tx)

txID := tx.ID()
tx.vm.state.DeleteStatus(txID)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We assume that transactions on disk with no status are accepted, so we just need to make sure to delete any previously existing statuses on disk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🎉

vms/avm/vm.go Outdated
@@ -579,7 +557,7 @@ func (vm *VM) initState(tx *txs.Tx) {
zap.Stringer("txID", txID),
)
vm.state.AddTx(tx)
vm.state.AddStatus(txID, choices.Accepted)
vm.state.DeleteStatus(txID)
Copy link
Contributor Author

@StephenButtolph StephenButtolph Jun 27, 2023

Choose a reason for hiding this comment

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

We assume that transactions on disk with no status are accepted, so we just need to make sure to delete any previously existing statuses on disk.

Here that should never happen - but for clarity I think it makes sense to explicitly remove the status anyways.

@@ -426,77 +419,6 @@ func TestVMFormat(t *testing.T) {
}
}

func TestTxCached(t *testing.T) {
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 were testing the UniqueTx caching behavior - which is now removed.

Comment on lines -580 to -586
firstTxStatus, err := env.vm.state.GetStatus(firstTx.ID())
_, err = env.vm.state.GetTx(firstTx.ID())
require.NoError(err)
require.Equal(choices.Accepted, firstTxStatus)

secondTxStatus, err := env.vm.state.GetStatus(secondTx.ID())
_, err = env.vm.state.GetTx(secondTx.ID())
require.NoError(err)
require.Equal(choices.Accepted, secondTxStatus)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GetTx only returns Accepted transactions now.

Choose a reason for hiding this comment

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

I don't think that's documented at the moment:

type ReadOnlyChain interface {
	avax.UTXOGetter

	GetTx(txID ids.ID) (*txs.Tx, error)
	GetBlockID(height uint64) (ids.ID, error)
	GetBlock(blkID ids.ID) (blocks.Block, error)
	GetLastAccepted() ids.ID
	GetTimestamp() time.Time
}

perhaps we should do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the DeleteStatus from the State interface. Now - the State interface returns txs that were AddTxed. The State interface no longer references statuses at all.

@StephenButtolph StephenButtolph marked this pull request as ready for review June 27, 2023 19:32
//
// TODO: Remove DeleteStatus after v1.11.x has activated and we can assume
// all nodes have pruned their statuses from disk.
DeleteStatus(id ids.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can assume all nodes have pruned their statuses from disk after v1.1.11.x has activated, why don't we just remove entire statusDB and statusCache instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After v1.11.x we will remove the statusDB and statusCache

@@ -75,18 +74,15 @@ func TestSetsAndGets(t *testing.T) {

env.vm.state.AddUTXO(utxo)
env.vm.state.AddTx(tx)
env.vm.state.AddStatus(txID, choices.Accepted)
env.vm.state.DeleteStatus(txID)

Choose a reason for hiding this comment

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

Can we document why we do this? It's not super obvious what we're doing here, and the test passes without this line. OTOH we're removing DeleteStatus soon so maybe we don't need to?

Copy link
Contributor Author

@StephenButtolph StephenButtolph Jun 28, 2023

Choose a reason for hiding this comment

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

It isn't needed - I felt it was most clear to always delete the status when accepting a tx to make it clear that the status will be reported correctly.

This is the same as deleting the status in the genesis initialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the DeleteStatus function entirely.

Copy link

@danlaine danlaine left a comment

Choose a reason for hiding this comment

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

just a few comments regarding comments

@StephenButtolph
Copy link
Contributor Author

I'm going to merge this - the mainnet sync is still ongoing but is expected to pass.

@StephenButtolph StephenButtolph merged commit c72d231 into dev Jun 28, 2023
@StephenButtolph StephenButtolph deleted the remove-statuses branch June 28, 2023 19:59
ramilexe pushed a commit to ConsiderItDone/avalanchego that referenced this pull request Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement vm This involves virtual machines
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants