Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Standardize P-Chain tx visitor order #3529

Merged
merged 33 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4c2605c
wip
StephenButtolph Nov 6, 2024
acf026a
comments
StephenButtolph Nov 6, 2024
bb0a605
merged
StephenButtolph Nov 6, 2024
0bf397a
Unexport AtomicTxExecutor
StephenButtolph Nov 6, 2024
5591626
nit
StephenButtolph Nov 6, 2024
0093c70
Unexport ProposalTxExecutor
StephenButtolph Nov 6, 2024
a0e6bcd
comment new function
StephenButtolph Nov 6, 2024
5e46925
nit
StephenButtolph Nov 6, 2024
706c833
Standardize standard tx executor
StephenButtolph Nov 7, 2024
3a01924
nit
StephenButtolph Nov 7, 2024
d7e00dd
nit
StephenButtolph Nov 7, 2024
56b0049
nit
StephenButtolph Nov 7, 2024
3540203
nit
StephenButtolph Nov 7, 2024
1bf8709
nit
StephenButtolph Nov 7, 2024
018b0aa
Comment
StephenButtolph Nov 7, 2024
bd6e10b
Remove P-chain txsmock package
StephenButtolph Nov 7, 2024
24c7d4b
nit
StephenButtolph Nov 7, 2024
833c04d
merged
StephenButtolph Nov 7, 2024
70a53b3
reduce diff
StephenButtolph Nov 7, 2024
26c3549
reduce diff
StephenButtolph Nov 7, 2024
877242f
reduce diff
StephenButtolph Nov 7, 2024
5110cfa
reduce diff
StephenButtolph Nov 7, 2024
e435ed7
reduce diff
StephenButtolph Nov 7, 2024
3750b1c
reduce diff
StephenButtolph Nov 7, 2024
687398e
reduce diff
StephenButtolph Nov 7, 2024
5a08505
reduce diff
StephenButtolph Nov 7, 2024
05d24ca
reduce diff
StephenButtolph Nov 7, 2024
37bede4
reduce diff
StephenButtolph Nov 7, 2024
3098c0b
reduce diff
StephenButtolph Nov 7, 2024
240f1e8
Standardize P-Chain tx visitor order
StephenButtolph Nov 7, 2024
0901618
Merge branch 'master' into standardize-p-chain-tx-vistors
StephenButtolph Nov 7, 2024
aedd8da
Merge branch 'standardize-p-chain-tx-vistors' into standardize-p-chai…
StephenButtolph Nov 7, 2024
e10a311
merged
StephenButtolph Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,32 +516,29 @@ func executeTx(
return false, err
}

executor := &txexecutor.StandardTxExecutor{
Backend: backend,
State: txDiff,
FeeCalculator: feeCalculator,
Tx: tx,
}

err = tx.Unsigned.Visit(executor)
txInputs, _, _, err := txexecutor.StandardTx(
backend,
feeCalculator,
tx,
txDiff,
)
if err != nil {
txID := tx.ID()
mempool.MarkDropped(txID, err)
return false, nil
}

if inputs.Overlaps(executor.Inputs) {
if inputs.Overlaps(txInputs) {
txID := tx.ID()
mempool.MarkDropped(txID, blockexecutor.ErrConflictingBlockTxs)
return false, nil
}
err = manager.VerifyUniqueInputs(parentID, executor.Inputs)
if err != nil {
if err := manager.VerifyUniqueInputs(parentID, txInputs); err != nil {
txID := tx.ID()
mempool.MarkDropped(txID, err)
return false, nil
}
inputs.Union(executor.Inputs)
inputs.Union(txInputs)

txDiff.AddTx(tx, status.Committed)
return true, txDiff.Apply(stateDiff)
Expand Down
14 changes: 7 additions & 7 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ func addSubnet(t *testing.T, env *environment) {
require.NoError(err)

feeCalculator := state.PickFeeCalculator(env.config, stateDiff)
executor := txexecutor.StandardTxExecutor{
Backend: &env.backend,
State: stateDiff,
FeeCalculator: feeCalculator,
Tx: testSubnet1,
}
require.NoError(testSubnet1.Unsigned.Visit(&executor))
_, _, _, err = txexecutor.StandardTx(
&env.backend,
feeCalculator,
testSubnet1,
stateDiff,
)
require.NoError(err)

stateDiff.AddTx(testSubnet1, status.Committed)
require.NoError(stateDiff.Apply(env.state))
Expand Down
14 changes: 7 additions & 7 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ func addSubnet(t testing.TB, env *environment) {
require.NoError(err)

feeCalculator := state.PickFeeCalculator(env.config, stateDiff)
executor := executor.StandardTxExecutor{
Backend: env.backend,
State: stateDiff,
FeeCalculator: feeCalculator,
Tx: testSubnet1,
}
require.NoError(testSubnet1.Unsigned.Visit(&executor))
_, _, _, err = executor.StandardTx(
env.backend,
feeCalculator,
testSubnet1,
stateDiff,
)
require.NoError(err)

stateDiff.AddTx(testSubnet1, status.Committed)
require.NoError(stateDiff.Apply(env.state))
Expand Down
13 changes: 7 additions & 6 deletions vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ func (m *manager) VerifyTx(tx *txs.Tx) error {
}

feeCalculator := state.PickFeeCalculator(m.txExecutorBackend.Config, stateDiff)
return tx.Unsigned.Visit(&executor.StandardTxExecutor{
Backend: m.txExecutorBackend,
State: stateDiff,
FeeCalculator: feeCalculator,
Tx: tx,
})
_, _, _, err = executor.StandardTx(
m.txExecutorBackend,
feeCalculator,
tx,
stateDiff,
)
return err
}

func (m *manager) VerifyUniqueInputs(blkID ids.ID, inputs set.Set[ids.ID]) error {
Expand Down
72 changes: 35 additions & 37 deletions vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,22 @@ func (v *verifier) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
}

feeCalculator := state.NewStaticFeeCalculator(v.txExecutorBackend.Config, currentTimestamp)
atomicExecutor := executor.AtomicTxExecutor{
Backend: v.txExecutorBackend,
FeeCalculator: feeCalculator,
ParentID: parentID,
StateVersions: v,
Tx: b.Tx,
}

if err := b.Tx.Unsigned.Visit(&atomicExecutor); err != nil {
onAcceptState, atomicInputs, atomicRequests, err := executor.AtomicTx(
v.txExecutorBackend,
feeCalculator,
parentID,
v,
b.Tx,
)
if err != nil {
txID := b.Tx.ID()
v.MarkDropped(txID, err) // cache tx as dropped
return fmt.Errorf("tx %s failed semantic verification: %w", txID, err)
return err
}

atomicExecutor.OnAccept.AddTx(b.Tx, status.Committed)
onAcceptState.AddTx(b.Tx, status.Committed)

if err := v.verifyUniqueInputs(parentID, atomicExecutor.Inputs); err != nil {
if err := v.verifyUniqueInputs(parentID, atomicInputs); err != nil {
return err
}

Expand All @@ -256,11 +255,11 @@ func (v *verifier) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
v.blkIDToState[blkID] = &blockState{
statelessBlock: b,

onAcceptState: atomicExecutor.OnAccept,
onAcceptState: onAcceptState,

inputs: atomicExecutor.Inputs,
timestamp: atomicExecutor.OnAccept.GetTimestamp(),
atomicRequests: atomicExecutor.AtomicRequests,
inputs: atomicInputs,
timestamp: onAcceptState.GetTimestamp(),
atomicRequests: atomicRequests,
verifiedHeights: set.Of(v.pChainHeight),
}
return nil
Expand Down Expand Up @@ -395,15 +394,14 @@ func (v *verifier) proposalBlock(
atomicRequests map[ids.ID]*atomic.Requests,
onAcceptFunc func(),
) error {
txExecutor := executor.ProposalTxExecutor{
OnCommitState: onCommitState,
OnAbortState: onAbortState,
Backend: v.txExecutorBackend,
FeeCalculator: feeCalculator,
Tx: tx,
}

if err := tx.Unsigned.Visit(&txExecutor); err != nil {
err := executor.ProposalTx(
v.txExecutorBackend,
feeCalculator,
tx,
onCommitState,
onAbortState,
)
if err != nil {
txID := tx.ID()
v.MarkDropped(txID, err) // cache tx as dropped
return err
Expand Down Expand Up @@ -519,30 +517,30 @@ func (v *verifier) processStandardTxs(txs []*txs.Tx, feeCalculator txfee.Calcula
atomicRequests = make(map[ids.ID]*atomic.Requests)
)
for _, tx := range txs {
txExecutor := executor.StandardTxExecutor{
Backend: v.txExecutorBackend,
State: diff,
FeeCalculator: feeCalculator,
Tx: tx,
}
if err := tx.Unsigned.Visit(&txExecutor); err != nil {
txInputs, txAtomicRequests, onAccept, err := executor.StandardTx(
v.txExecutorBackend,
feeCalculator,
tx,
diff,
)
if err != nil {
txID := tx.ID()
v.MarkDropped(txID, err) // cache tx as dropped
return nil, nil, nil, err
}
// ensure it doesn't overlap with current input batch
if inputs.Overlaps(txExecutor.Inputs) {
if inputs.Overlaps(txInputs) {
return nil, nil, nil, ErrConflictingBlockTxs
}
// Add UTXOs to batch
inputs.Union(txExecutor.Inputs)
inputs.Union(txInputs)

diff.AddTx(tx, status.Committed)
if txExecutor.OnAccept != nil {
funcs = append(funcs, txExecutor.OnAccept)
if onAccept != nil {
funcs = append(funcs, onAccept)
}

for chainID, txRequests := range txExecutor.AtomicRequests {
for chainID, txRequests := range txAtomicRequests {
// Add/merge in the atomic requests represented by [tx]
chainRequests, exists := atomicRequests[chainID]
if !exists {
Expand Down
8 changes: 4 additions & 4 deletions vms/platformvm/metrics/tx_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ func (m *txMetrics) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) er
return nil
}

func (m *txMetrics) ConvertSubnetTx(*txs.ConvertSubnetTx) error {
func (m *txMetrics) BaseTx(*txs.BaseTx) error {
m.numTxs.With(prometheus.Labels{
txLabel: "convert_subnet",
txLabel: "base",
}).Inc()
return nil
}

func (m *txMetrics) BaseTx(*txs.BaseTx) error {
func (m *txMetrics) ConvertSubnetTx(*txs.ConvertSubnetTx) error {
m.numTxs.With(prometheus.Labels{
txLabel: "base",
txLabel: "convert_subnet",
}).Inc()
return nil
}
Loading
Loading