Skip to content

Commit

Permalink
Remove GetTx from the DAGVM interface (ava-labs#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jun 22, 2023
1 parent 2fc0d3b commit d2899e6
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 190 deletions.
18 changes: 3 additions & 15 deletions indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/ava-labs/avalanchego/database/versiondb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block/mocks"
Expand Down Expand Up @@ -324,21 +322,11 @@ func TestIndexer(t *testing.T) {
txID, txBytes := ids.GenerateTestID(), utils.RandomBytes(32)
expectedTx := Container{
ID: txID,
Bytes: blkBytes,
Bytes: txBytes,
Timestamp: now.UnixNano(),
}
// Mocked VM knows about this tx now
dagVM.EXPECT().GetTx(gomock.Any(), txID).Return(
&snowstorm.TestTx{
TestDecidable: choices.TestDecidable{
IDV: txID,
StatusV: choices.Accepted,
},
BytesV: txBytes,
}, nil,
).AnyTimes()

require.NoError(config.TxAcceptorGroup.Accept(chain2Ctx, txID, blkBytes))

require.NoError(config.TxAcceptorGroup.Accept(chain2Ctx, txID, txBytes))

txIdx := idxr.txIndices[chain2Ctx.ChainID]
require.NotNil(txIdx)
Expand Down
15 changes: 0 additions & 15 deletions snow/engine/avalanche/vertex/mock_vm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions snow/engine/avalanche/vertex/test_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ var (
type TestVM struct {
block.TestVM

CantLinearize, CantParse, CantGet bool
CantLinearize, CantParse bool

LinearizeF func(context.Context, ids.ID) error
ParseTxF func(context.Context, []byte) (snowstorm.Tx, error)
GetTxF func(context.Context, ids.ID) (snowstorm.Tx, error)
}

func (vm *TestVM) Default(cant bool) {
vm.TestVM.Default(cant)

vm.CantParse = cant
vm.CantGet = cant
}

func (vm *TestVM) Linearize(ctx context.Context, stopVertexID ids.ID) error {
Expand All @@ -56,13 +54,3 @@ func (vm *TestVM) ParseTx(ctx context.Context, b []byte) (snowstorm.Tx, error) {
}
return nil, errParse
}

func (vm *TestVM) GetTx(ctx context.Context, txID ids.ID) (snowstorm.Tx, error) {
if vm.GetTxF != nil {
return vm.GetTxF(ctx, txID)
}
if vm.CantGet && vm.T != nil {
require.FailNow(vm.T, errGet.Error())
}
return nil, errGet
}
7 changes: 0 additions & 7 deletions snow/engine/avalanche/vertex/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ type LinearizableVM interface {
// implement
type DAGVM interface {
block.ChainVM
Getter

// Convert a stream of bytes to a transaction or return an error
ParseTx(ctx context.Context, txBytes []byte) (snowstorm.Tx, error)
}

// Getter defines the functionality for fetching a tx/block by its ID.
type Getter interface {
// Retrieve a transaction that was submitted previously
GetTx(ctx context.Context, txID ids.ID) (snowstorm.Tx, error)
}
10 changes: 0 additions & 10 deletions vms/avm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,6 @@ func (vm *VM) ParseTx(_ context.Context, bytes []byte) (snowstorm.Tx, error) {
return tx, nil
}

func (vm *VM) GetTx(_ context.Context, txID ids.ID) (snowstorm.Tx, error) {
tx := &UniqueTx{
vm: vm,
txID: txID,
}
// Verify must be called in the case the that tx was flushed from the unique
// cache.
return tx, tx.verifyWithoutCacheWrites()
}

/*
******************************************************************************
********************************** JSON API **********************************
Expand Down
95 changes: 0 additions & 95 deletions vms/avm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,101 +582,6 @@ func TestTxAcceptAfterParseTx(t *testing.T) {
require.Equal(choices.Accepted, secondTxStatus)
}

func TestTxAcceptAfterGetTx(t *testing.T) {
require := require.New(t)

env := setup(t, &envConfig{
notLinearized: true,
})
defer func() {
require.NoError(env.vm.Shutdown(context.Background()))
env.vm.ctx.Lock.Unlock()
}()

key := keys[0]
firstTx := &txs.Tx{Unsigned: &txs.BaseTx{
BaseTx: avax.BaseTx{
NetworkID: constants.UnitTestID,
BlockchainID: chainID,
Ins: []*avax.TransferableInput{{
UTXOID: avax.UTXOID{
TxID: env.genesisTx.ID(),
OutputIndex: 2,
},
Asset: avax.Asset{ID: env.genesisTx.ID()},
In: &secp256k1fx.TransferInput{
Amt: startBalance,
Input: secp256k1fx.Input{
SigIndices: []uint32{
0,
},
},
},
}},
Outs: []*avax.TransferableOutput{{
Asset: avax.Asset{ID: env.genesisTx.ID()},
Out: &secp256k1fx.TransferOutput{
Amt: startBalance - env.vm.TxFee,
OutputOwners: secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{key.PublicKey().Address()},
},
},
}},
},
}}
require.NoError(firstTx.SignSECP256K1Fx(env.vm.parser.Codec(), [][]*secp256k1.PrivateKey{{key}}))

secondTx := &txs.Tx{Unsigned: &txs.BaseTx{
BaseTx: avax.BaseTx{
NetworkID: constants.UnitTestID,
BlockchainID: chainID,
Ins: []*avax.TransferableInput{{
UTXOID: avax.UTXOID{
TxID: firstTx.ID(),
OutputIndex: 0,
},
Asset: avax.Asset{ID: env.genesisTx.ID()},
In: &secp256k1fx.TransferInput{
Amt: startBalance - env.vm.TxFee,
Input: secp256k1fx.Input{
SigIndices: []uint32{
0,
},
},
},
}},
},
}}
require.NoError(secondTx.SignSECP256K1Fx(env.vm.parser.Codec(), [][]*secp256k1.PrivateKey{{key}}))

_, err := env.vm.ParseTx(context.Background(), firstTx.Bytes())
require.NoError(err)

fetchedFirstTx, err := env.vm.GetTx(context.Background(), firstTx.ID())
require.NoError(err)

require.NoError(fetchedFirstTx.Verify(context.Background()))
require.NoError(fetchedFirstTx.Accept(context.Background()))

_, err = env.vm.ParseTx(context.Background(), secondTx.Bytes())
require.NoError(err)

fetchedSecondTx, err := env.vm.GetTx(context.Background(), secondTx.ID())
require.NoError(err)

require.NoError(fetchedSecondTx.Verify(context.Background()))
require.NoError(fetchedSecondTx.Accept(context.Background()))

firstTxStatus, err := env.vm.state.GetStatus(firstTx.ID())
require.NoError(err)
require.Equal(choices.Accepted, firstTxStatus)

secondTxStatus, err := env.vm.state.GetStatus(secondTx.ID())
require.NoError(err)
require.Equal(choices.Accepted, secondTxStatus)
}

// Test issuing an import transaction.
func TestIssueImportTx(t *testing.T) {
require := require.New(t)
Expand Down
4 changes: 0 additions & 4 deletions vms/metervm/vertex_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
type vertexMetrics struct {
parse,
parseErr,
get,
getErr,
verify,
verifyErr,
accept,
Expand All @@ -28,8 +26,6 @@ func (m *vertexMetrics) Initialize(
errs := wrappers.Errs{}
m.parse = newAverager(namespace, "parse_tx", reg, &errs)
m.parseErr = newAverager(namespace, "parse_tx_err", reg, &errs)
m.get = newAverager(namespace, "get_tx", reg, &errs)
m.getErr = newAverager(namespace, "get_tx_err", reg, &errs)
m.verify = newAverager(namespace, "verify_tx", reg, &errs)
m.verifyErr = newAverager(namespace, "verify_tx_err", reg, &errs)
m.accept = newAverager(namespace, "accept", reg, &errs)
Expand Down
17 changes: 0 additions & 17 deletions vms/metervm/vertex_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/ava-labs/avalanchego/api/metrics"
"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
Expand Down Expand Up @@ -93,22 +92,6 @@ func (vm *vertexVM) ParseTx(ctx context.Context, b []byte) (snowstorm.Tx, error)
}, nil
}

func (vm *vertexVM) GetTx(ctx context.Context, txID ids.ID) (snowstorm.Tx, error) {
start := vm.clock.Time()
tx, err := vm.LinearizableVMWithEngine.GetTx(ctx, txID)
end := vm.clock.Time()
duration := float64(end.Sub(start))
if err != nil {
vm.vertexMetrics.getErr.Observe(duration)
return nil, err
}
vm.vertexMetrics.get.Observe(duration)
return &meterTx{
Tx: tx,
vm: vm,
}, nil
}

type meterTx struct {
snowstorm.Tx

Expand Down
14 changes: 0 additions & 14 deletions vms/tracedvm/vertex_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
oteltrace "go.opentelemetry.io/otel/trace"

"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
Expand Down Expand Up @@ -72,16 +71,3 @@ func (vm *vertexVM) ParseTx(ctx context.Context, txBytes []byte) (snowstorm.Tx,
tracer: vm.tracer,
}, err
}

func (vm *vertexVM) GetTx(ctx context.Context, txID ids.ID) (snowstorm.Tx, error) {
ctx, span := vm.tracer.Start(ctx, "vertexVM.GetTx", oteltrace.WithAttributes(
attribute.Stringer("txID", txID),
))
defer span.End()

tx, err := vm.LinearizableVMWithEngine.GetTx(ctx, txID)
return &tracedTx{
Tx: tx,
tracer: vm.tracer,
}, err
}

0 comments on commit d2899e6

Please sign in to comment.