Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Cosmetic fixes. Tests fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
devintegral3 committed Apr 13, 2020
1 parent a4f9e41 commit 525df63
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 53 deletions.
2 changes: 1 addition & 1 deletion cmd/tx-storm/txgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

func TestGenerator(t *testing.T) {
t.Skip("example only")
g := newTxGenerator(0, 20, 0)
g := newTxGenerator(0, 20, 0, 4003)
for i := 0; i < 2*len(g.accs); i++ {
tx := g.Yield()
t.Log(tx.Info.String(), tx.Raw.Nonce(), tx.Raw.Value())
Expand Down
28 changes: 6 additions & 22 deletions ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/Fantom-foundation/go-lachesis/inter"
"github.com/Fantom-foundation/go-lachesis/inter/idx"
lachesisparams "github.com/Fantom-foundation/go-lachesis/lachesis/params"
"github.com/Fantom-foundation/go-lachesis/utils"
)

const (
Expand Down Expand Up @@ -396,7 +397,7 @@ func (s *PrivateAccountAPI) SendTrustedTransaction(ctx context.Context, args Sen
log.Warn("Failed transaction send attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
return common.Hash{}, err
}
return SubmitTrustedTransaction(ctx, s.b, signed)
return SubmitTransaction(ctx, s.b, signed, true)
}

// SignTransaction will create a transaction from the given arguments and
Expand Down Expand Up @@ -1531,27 +1532,10 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
}

// SubmitTransaction is a helper function that submits tx to txPool and logs a message.
func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) {
if err := b.SendTx(ctx, tx); err != nil {
return common.Hash{}, err
}
if tx.To() == nil {
signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number)
from, err := types.Sender(signer, tx)
if err != nil {
return common.Hash{}, err
}
addr := crypto.CreateAddress(from, tx.Nonce())
log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())
} else {
log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
}
return tx.Hash(), nil
}
func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction, flags ...bool) (common.Hash, error) {
trusted := utils.ParseFlag(flags, 0, false)

// SubmitTrustedTransaction is a helper function that submits trusted tx to txPool and logs a message.
func SubmitTrustedTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) {
if err := b.SendTrustedTx(ctx, tx); err != nil {
if err := b.SendTx(ctx, tx, trusted); err != nil {
return common.Hash{}, err
}
if tx.To() == nil {
Expand All @@ -1563,7 +1547,7 @@ func SubmitTrustedTransaction(ctx context.Context, b Backend, tx *types.Transact
addr := crypto.CreateAddress(from, tx.Nonce())
log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())
} else {
log.Info("Submitted trusted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
}
return tx.Hash(), nil
}
Expand Down
3 changes: 1 addition & 2 deletions ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ type Backend interface {
GetEVM(ctx context.Context, msg evmcore.Message, state *state.StateDB, header *evmcore.EvmHeader) (*vm.EVM, func() error, error)

// Transaction pool API
SendTx(ctx context.Context, signedTx *types.Transaction) error
SendTrustedTx(ctx context.Context, signedTx *types.Transaction) error
SendTx(ctx context.Context, signedTx *types.Transaction, flags ...bool) error
GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, uint64, uint64, error)
GetPoolTransactions() (types.Transactions, error)
GetPoolTransaction(txHash common.Hash) *types.Transaction
Expand Down
4 changes: 1 addition & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Fantom-foundation/go-ethereum v1.9.8-ftm-0.5 h1:XYmSAmF4j3I0a+F9+Byhcz7Zg7Hw8p1Vt3B/6gfs9HA=
github.com/Fantom-foundation/go-ethereum v1.9.8-ftm-0.5/go.mod h1:arcJDscBoRuY4gwPHUuFztJEyFZWHLUgBGXUBcr5ARY=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.5/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
Expand Down Expand Up @@ -82,6 +80,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/devintegral3/go-ethereum v1.9.8-ftm-0.6 h1:1DEbV3Q0VXdnVp0IpsRruTbNkNfAoCQqEO/MZ+TEAfc=
github.com/devintegral3/go-ethereum v1.9.8-ftm-0.6/go.mod h1:arcJDscBoRuY4gwPHUuFztJEyFZWHLUgBGXUBcr5ARY=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
Expand All @@ -99,7 +98,6 @@ github.com/elastic/gosigar v0.10.5 h1:GzPQ+78RaAb4J63unidA/JavQRKrB6s8IOzN6Ib59j
github.com/elastic/gosigar v0.10.5/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/ethereum/go-ethereum v1.9.8/go.mod h1:N68Ktr8bkyajaEy6D8CSANxkhUxcnVjTmp9sKdKd8OI=
github.com/evalphobia/logrus_sentry v0.8.2 h1:dotxHq+YLZsT1Bb45bB5UQbfCh3gM/nFFetyN46VoDQ=
github.com/evalphobia/logrus_sentry v0.8.2/go.mod h1:pKcp+vriitUqu9KiWj/VRFbRfFNUwz95/UkgG8a6MNc=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 h1:BBso6MBKW8ncyZLv37o+KNyy0HrrHgfnOaGQC2qvN+A=
Expand Down
25 changes: 15 additions & 10 deletions gossip/dummy_tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

// dummyTxPool is a fake, helper transaction pool for testing purposes
type dummyTxPool struct {
txFeed notify.Feed
pool []*types.Transaction // Collection of all transactions
trusted []*types.Transaction // Collection of all transactions
added chan<- []*types.Transaction // Notification channel for new transactions
txFeed notify.Feed
pool []*types.Transaction // Collection of all transactions
trusted []*types.Transaction
added chan<- []*types.Transaction // Notification channel for new transactions

lock sync.RWMutex // Protects the transaction pool
}
Expand Down Expand Up @@ -50,23 +50,28 @@ func (p *dummyTxPool) Pending() (map[common.Address]types.Transactions, error) {
return batches, nil
}

func (p *dummyTxPool) Trusted() (map[common.Address]types.Transactions, error) {
func (p *dummyTxPool) Trusted(clear bool) (map[common.Address]types.Transactions, error) {
if p.trusted == nil {
return map[common.Address]types.Transactions{}, nil
}

p.lock.RLock()
defer p.lock.RUnlock()

batches := make(map[common.Address]types.Transactions)
trusted := make(map[common.Address]types.Transactions)
for _, tx := range p.trusted {
from, _ := types.Sender(types.HomesteadSigner{}, tx)
batches[from] = append(batches[from], tx)

if trusted[from] == nil {
trusted[from] = make(types.Transactions, 0, 1)
}
trusted[from] = append(trusted[from], tx)
}
for _, batch := range batches {
sort.Sort(types.TxByNonce(batch))
if clear {
p.trusted = make(types.Transactions, 0)
}
return batches, nil

return trusted, nil
}

func (p *dummyTxPool) SubscribeNewTxsNotify(ch chan<- evmcore.NewTxsNotify) notify.Subscription {
Expand Down
25 changes: 10 additions & 15 deletions gossip/ethapi_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/Fantom-foundation/go-lachesis/lachesis/genesis/sfc"
"github.com/Fantom-foundation/go-lachesis/lachesis/genesis/sfc/sfcpos"
"github.com/Fantom-foundation/go-lachesis/tracing"
"github.com/Fantom-foundation/go-lachesis/utils"
)

var ErrNotImplemented = func(name string) error { return errors.New(name + " method is not implemented yet") }
Expand Down Expand Up @@ -325,24 +326,18 @@ func (b *EthAPIBackend) GetEVM(ctx context.Context, msg evmcore.Message, state *
return vm.NewEVM(context, state, config, vm.Config{}), vmError, nil
}

func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
err := b.svc.txpool.AddLocal(signedTx)
if err == nil {
// NOTE: only sent txs tracing, see TxPool.addTxs() for all
tracing.StartTx(signedTx.Hash(), "EthAPIBackend.SendTx()")
// TODO: txLatency cleaning, possible memory leak
if metrics.Enabled {
txLatency.Start(signedTx.Hash())
}
}
return err
}
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction, flags ...bool) error {
trusted := utils.ParseFlag(flags, 0, false)

func (b *EthAPIBackend) SendTrustedTx(ctx context.Context, signedTx *types.Transaction) error {
err := b.svc.txpool.AddTrusted(signedTx)
var err error
if trusted {
err = b.svc.txpool.AddTrusted(signedTx)
} else {
err = b.svc.txpool.AddLocal(signedTx)
}
if err == nil {
// NOTE: only sent txs tracing, see TxPool.addTxs() for all
tracing.StartTx(signedTx.Hash(), "EthAPIBackend.SendTrustedTx()")
tracing.StartTx(signedTx.Hash(), "EthAPIBackend.SendTx()")
// TODO: txLatency cleaning, possible memory leak
if metrics.Enabled {
txLatency.Start(signedTx.Hash())
Expand Down

0 comments on commit 525df63

Please sign in to comment.