Skip to content

Commit

Permalink
Remove AddUnverifiedTx from Builder (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Nov 16, 2023
1 parent e8ef4ad commit 01a1bbe
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 78 deletions.
8 changes: 0 additions & 8 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ type Builder interface {
mempool.BlockTimer
Network

// AddUnverifiedTx verifier the tx before adding it to mempool
AddUnverifiedTx(tx *txs.Tx) error

// BuildBlock is called on timer clock to attempt to create
// next block
BuildBlock(context.Context) (snowman.Block, error)
Expand Down Expand Up @@ -100,11 +97,6 @@ func New(
return builder
}

// AddUnverifiedTx verifies a transaction and attempts to add it to the mempool
func (b *builder) AddUnverifiedTx(tx *txs.Tx) error {
return b.Network.IssueTx(context.TODO(), tx)
}

// BuildBlock builds a block to be added to consensus.
// This method removes the transactions from the returned
// blocks from the mempool.
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/block/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestBlockBuilderAddLocalTx(t *testing.T) {
env.sender.SendAppGossipF = func(context.Context, []byte) error {
return nil
}
require.NoError(env.Builder.AddUnverifiedTx(tx))
require.NoError(env.Builder.IssueTx(context.Background(), tx))
require.True(env.mempool.Has(txID))

// show that build block include that tx and removes it from mempool
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/block/builder/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewNetwork(
}
}

func (n *network) AppGossip(_ context.Context, nodeID ids.NodeID, msgBytes []byte) error {
func (n *network) AppGossip(ctx context.Context, nodeID ids.NodeID, msgBytes []byte) error {
n.ctx.Log.Debug("called AppGossip message handler",
zap.Stringer("nodeID", nodeID),
zap.Int("messageLen", len(msgBytes)),
Expand Down Expand Up @@ -115,7 +115,7 @@ func (n *network) AppGossip(_ context.Context, nodeID ids.NodeID, msgBytes []byt
}

// add to mempool
if err := n.blkBuilder.AddUnverifiedTx(tx); err != nil {
if err := n.IssueTx(ctx, tx); err != nil {
n.ctx.Log.Debug("tx failed verification",
zap.Stringer("nodeID", nodeID),
zap.Error(err),
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/block/builder/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestMempoolNewLocaTxIsGossiped(t *testing.T) {
tx := getValidTx(env.txBuilder, t)
txID := tx.ID()

require.NoError(env.Builder.AddUnverifiedTx(tx))
require.NoError(env.Builder.IssueTx(context.Background(), tx))
require.NotNil(gossipedBytes)

// show gossiped bytes can be decoded to the original tx
Expand Down
32 changes: 16 additions & 16 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ type AddValidatorArgs struct {

// AddValidator creates and signs and issues a transaction to add a validator to
// the primary network
func (s *Service) AddValidator(_ *http.Request, args *AddValidatorArgs, reply *api.JSONTxIDChangeAddr) error {
func (s *Service) AddValidator(req *http.Request, args *AddValidatorArgs, reply *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "addValidator"),
Expand Down Expand Up @@ -1284,7 +1284,7 @@ func (s *Service) AddValidator(_ *http.Request, args *AddValidatorArgs, reply *a

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand All @@ -1299,7 +1299,7 @@ type AddDelegatorArgs struct {

// AddDelegator creates and signs and issues a transaction to add a delegator to
// the primary network
func (s *Service) AddDelegator(_ *http.Request, args *AddDelegatorArgs, reply *api.JSONTxIDChangeAddr) error {
func (s *Service) AddDelegator(req *http.Request, args *AddDelegatorArgs, reply *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "addDelegator"),
Expand Down Expand Up @@ -1394,7 +1394,7 @@ func (s *Service) AddDelegator(_ *http.Request, args *AddDelegatorArgs, reply *a

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand All @@ -1410,7 +1410,7 @@ type AddSubnetValidatorArgs struct {

// AddSubnetValidator creates and signs and issues a transaction to add a
// validator to a subnet other than the primary network
func (s *Service) AddSubnetValidator(_ *http.Request, args *AddSubnetValidatorArgs, response *api.JSONTxIDChangeAddr) error {
func (s *Service) AddSubnetValidator(req *http.Request, args *AddSubnetValidatorArgs, response *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "addSubnetValidator"),
Expand Down Expand Up @@ -1500,7 +1500,7 @@ func (s *Service) AddSubnetValidator(_ *http.Request, args *AddSubnetValidatorAr

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand All @@ -1515,7 +1515,7 @@ type CreateSubnetArgs struct {

// CreateSubnet creates and signs and issues a transaction to create a new
// subnet
func (s *Service) CreateSubnet(_ *http.Request, args *CreateSubnetArgs, response *api.JSONTxIDChangeAddr) error {
func (s *Service) CreateSubnet(req *http.Request, args *CreateSubnetArgs, response *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "createSubnet"),
Expand Down Expand Up @@ -1576,7 +1576,7 @@ func (s *Service) CreateSubnet(_ *http.Request, args *CreateSubnetArgs, response

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand All @@ -1599,7 +1599,7 @@ type ExportAVAXArgs struct {

// ExportAVAX exports AVAX from the P-Chain to the X-Chain
// It must be imported on the X-Chain to complete the transfer
func (s *Service) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *api.JSONTxIDChangeAddr) error {
func (s *Service) ExportAVAX(req *http.Request, args *ExportAVAXArgs, response *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "exportAVAX"),
Expand Down Expand Up @@ -1672,7 +1672,7 @@ func (s *Service) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *ap

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand All @@ -1691,7 +1691,7 @@ type ImportAVAXArgs struct {

// ImportAVAX issues a transaction to import AVAX from the X-chain. The AVAX
// must have already been exported from the X-Chain.
func (s *Service) ImportAVAX(_ *http.Request, args *ImportAVAXArgs, response *api.JSONTxIDChangeAddr) error {
func (s *Service) ImportAVAX(req *http.Request, args *ImportAVAXArgs, response *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "importAVAX"),
Expand Down Expand Up @@ -1757,7 +1757,7 @@ func (s *Service) ImportAVAX(_ *http.Request, args *ImportAVAXArgs, response *ap

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -1787,7 +1787,7 @@ type CreateBlockchainArgs struct {
}

// CreateBlockchain issues a transaction to create a new blockchain
func (s *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchainArgs, response *api.JSONTxIDChangeAddr) error {
func (s *Service) CreateBlockchain(req *http.Request, args *CreateBlockchainArgs, response *api.JSONTxIDChangeAddr) error {
s.vm.ctx.Log.Warn("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "createBlockchain"),
Expand Down Expand Up @@ -1881,7 +1881,7 @@ func (s *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchainArgs,

return utils.Err(
err,
s.vm.Builder.AddUnverifiedTx(tx),
s.vm.Builder.IssueTx(req.Context(), tx),
user.Close(),
)
}
Expand Down Expand Up @@ -2155,7 +2155,7 @@ func (s *Service) GetBlockchains(_ *http.Request, _ *struct{}, response *GetBloc
return nil
}

func (s *Service) IssueTx(_ *http.Request, args *api.FormattedTx, response *api.JSONTxID) error {
func (s *Service) IssueTx(req *http.Request, args *api.FormattedTx, response *api.JSONTxID) error {
s.vm.ctx.Log.Debug("API called",
zap.String("service", "platform"),
zap.String("method", "issueTx"),
Expand All @@ -2173,7 +2173,7 @@ func (s *Service) IssueTx(_ *http.Request, args *api.FormattedTx, response *api.
s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

if err := s.vm.Builder.AddUnverifiedTx(tx); err != nil {
if err := s.vm.Builder.IssueTx(req.Context(), tx); err != nil {
return fmt.Errorf("couldn't issue tx: %w", err)
}

Expand Down
6 changes: 3 additions & 3 deletions vms/platformvm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ func TestGetTxStatus(t *testing.T) {
service.vm.ctx.Lock.Lock()

// put the chain in existing chain list
err = service.vm.Builder.AddUnverifiedTx(tx)
err = service.vm.Builder.IssueTx(context.Background(), tx)
require.ErrorIs(err, database.ErrNotFound) // Missing shared memory UTXO

mutableSharedMemory.SharedMemory = sm

require.NoError(service.vm.Builder.AddUnverifiedTx(tx))
require.NoError(service.vm.Builder.IssueTx(context.Background(), tx))

block, err := service.vm.BuildBlock(context.Background())
require.NoError(err)
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestGetTx(t *testing.T) {

service.vm.ctx.Lock.Lock()

require.NoError(service.vm.Builder.AddUnverifiedTx(tx))
require.NoError(service.vm.Builder.IssueTx(context.Background(), tx))

blk, err := service.vm.BuildBlock(context.Background())
require.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/validator_set_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func addPrimaryValidatorWithoutBLSKey(vm *VM, data *validatorInputData) (*state.

func internalAddValidator(vm *VM, signedTx *txs.Tx) (*state.Staker, error) {
stakerTx := signedTx.Unsigned.(txs.StakerTx)
if err := vm.Builder.AddUnverifiedTx(signedTx); err != nil {
if err := vm.Builder.IssueTx(context.Background(), signedTx); err != nil {
return nil, fmt.Errorf("could not add tx to mempool: %w", err)
}

Expand Down Expand Up @@ -802,7 +802,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) {
if err != nil {
return nil, ids.Empty, err
}
if err := vm.Builder.AddUnverifiedTx(testSubnet1); err != nil {
if err := vm.Builder.IssueTx(context.Background(), testSubnet1); err != nil {
return nil, ids.Empty, err
}

Expand Down
Loading

0 comments on commit 01a1bbe

Please sign in to comment.