Skip to content

Commit

Permalink
fix todos
Browse files Browse the repository at this point in the history
  • Loading branch information
temaniarpit27 committed Sep 13, 2023
1 parent 986486b commit feea10a
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 140 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func MakeTopics(query ...[]interface{}) ([][]common.Hash, error) {
copy(topic[:], hash[:])

default:
// todo(rjl493456442) according solidity documentation, indexed event
// TODO (rjl493456442) according solidity documentation, indexed event
// parameters that are not value types i.e. arrays and structs are not
// stored directly but instead a keccak256-hash of an encoding is stored.
//
Expand Down
1 change: 0 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) {
s.SetNonce(addr, sr.GetNonce(addr))
case CodePath:
s.SetCode(addr, sr.GetCode(addr))
// TODO - Arpit -----------------
case SuicidePath:
stateObject := sr.getDeletedStateObject(addr)
if stateObject != nil && stateObject.deleted {
Expand Down
3 changes: 2 additions & 1 deletion core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ type Config struct {
AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts

Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
AllowUnprotectedTxs bool // Allow non-EIP-155 transactions
}

// DefaultConfig contains the default configurations for the transaction pool.
Expand Down
14 changes: 13 additions & 1 deletion core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ func (p *TxPool) Pending(enforceTips bool) map[common.Address][]*LazyTransaction

// SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending
// events to the given channel.
// TODO - Arpit
func (p *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
subs := make([]event.Subscription, len(p.subpools))
for i, subpool := range p.subpools {
Expand Down Expand Up @@ -359,6 +358,19 @@ func (p *TxPool) Nonce(addr common.Address) uint64 {
return nonce
}

// Stats retrieves the current pool stats, namely the number of pending and the
// number of queued (non-executable) transactions.
func (p *TxPool) Stats() (int, int) {
var runnable, blocked int
for _, subpool := range p.subpools {
run, block := subpool.Stats()

runnable += run
blocked += block
}
return runnable, blocked
}

// // Stats retrieves the current pool stats, namely the number of pending and the
// // number of queued (non-executable) transactions.
// func (p *TxPool) Stats() (int, int) {
Expand Down
162 changes: 80 additions & 82 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package types

import (
"bytes"
"container/heap"
"errors"
"io"
"math/big"
Expand Down Expand Up @@ -531,21 +530,20 @@ type TxWithMinerFee struct {
minerFee *uint256.Int
}

// TODO - Arpit
// NewTxWithMinerFee creates a wrapped transaction, calculating the effective
// miner gasTipCap if a base fee is provided.
// Returns error in case of a negative effective miner gasTipCap.
func NewTxWithMinerFee(tx *Transaction, baseFee *uint256.Int) (*TxWithMinerFee, error) {
// minerFee, err := tx.EffectiveGasTipUnit(baseFee)
// if err != nil {
// return nil, err
// }
// // NewTxWithMinerFee creates a wrapped transaction, calculating the effective
// // miner gasTipCap if a base fee is provided.
// // Returns error in case of a negative effective miner gasTipCap.
// func NewTxWithMinerFee(tx *Transaction, baseFee *uint256.Int) (*TxWithMinerFee, error) {
// // minerFee, err := tx.EffectiveGasTipUnit(baseFee)
// // if err != nil {
// // return nil, err
// // }

return &TxWithMinerFee{
tx: tx,
minerFee: uint256.NewInt(1),
}, nil
}
// return &TxWithMinerFee{
// tx: tx,
// minerFee: uint256.NewInt(1),
// }, nil
// }

// TxByPriceAndTime implements both the sort and the heap interface, making it useful
// for all at once sorting as well as individually adding and removing elements.
Expand Down Expand Up @@ -623,70 +621,70 @@ func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transa
}
}*/

func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions, baseFee *uint256.Int) *TransactionsByPriceAndNonce {
// Initialize a price and received time based heap with the head transactions
heads := make(TxByPriceAndTime, 0, len(txs))

for from, accTxs := range txs {
if len(accTxs) == 0 {
continue
}

acc, _ := Sender(signer, accTxs[0])
wrapped, err := NewTxWithMinerFee(accTxs[0], baseFee)

// Remove transaction if sender doesn't match from, or if wrapping fails.
if acc != from || err != nil {
delete(txs, from)
continue
}

heads = append(heads, wrapped)
txs[from] = accTxs[1:]
}

heap.Init(&heads)

// Assemble and return the transaction set
return &TransactionsByPriceAndNonce{
txs: txs,
heads: heads,
signer: signer,
baseFee: baseFee,
}
}

// Peek returns the next transaction by price.
func (t *TransactionsByPriceAndNonce) Peek() *Transaction {
if len(t.heads) == 0 {
return nil
}

return t.heads[0].tx
}

// Shift replaces the current best head with the next one from the same account.
func (t *TransactionsByPriceAndNonce) Shift() {
acc, _ := Sender(t.signer, t.heads[0].tx)
if txs, ok := t.txs[acc]; ok && len(txs) > 0 {
if wrapped, err := NewTxWithMinerFee(txs[0], t.baseFee); err == nil {
t.heads[0], t.txs[acc] = wrapped, txs[1:]
heap.Fix(&t.heads, 0)

return
}
}

heap.Pop(&t.heads)
}

func (t *TransactionsByPriceAndNonce) GetTxs() int {
return len(t.txs)
}

// Pop removes the best transaction, *not* replacing it with the next one from
// the same account. This should be used when a transaction cannot be executed
// and hence all subsequent ones should be discarded from the same account.
func (t *TransactionsByPriceAndNonce) Pop() {
heap.Pop(&t.heads)
}
// func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions, baseFee *uint256.Int) *TransactionsByPriceAndNonce {
// // Initialize a price and received time based heap with the head transactions
// heads := make(TxByPriceAndTime, 0, len(txs))

// for from, accTxs := range txs {
// if len(accTxs) == 0 {
// continue
// }

// acc, _ := Sender(signer, accTxs[0])
// wrapped, err := NewTxWithMinerFee(accTxs[0], baseFee)

// // Remove transaction if sender doesn't match from, or if wrapping fails.
// if acc != from || err != nil {
// delete(txs, from)
// continue
// }

// heads = append(heads, wrapped)
// txs[from] = accTxs[1:]
// }

// heap.Init(&heads)

// // Assemble and return the transaction set
// return &TransactionsByPriceAndNonce{
// txs: txs,
// heads: heads,
// signer: signer,
// baseFee: baseFee,
// }
// }

// // Peek returns the next transaction by price.
// func (t *TransactionsByPriceAndNonce) Peek() *Transaction {
// if len(t.heads) == 0 {
// return nil
// }

// return t.heads[0].tx
// }

// // Shift replaces the current best head with the next one from the same account.
// func (t *TransactionsByPriceAndNonce) Shift() {
// acc, _ := Sender(t.signer, t.heads[0].tx)
// if txs, ok := t.txs[acc]; ok && len(txs) > 0 {
// if wrapped, err := NewTxWithMinerFee(txs[0], t.baseFee); err == nil {
// t.heads[0], t.txs[acc] = wrapped, txs[1:]
// heap.Fix(&t.heads, 0)

// return
// }
// }

// heap.Pop(&t.heads)
// }

// func (t *TransactionsByPriceAndNonce) GetTxs() int {
// return len(t.txs)
// }

// // Pop removes the best transaction, *not* replacing it with the next one from
// // the same account. This should be used when a transaction cannot be executed
// // and hence all subsequent ones should be discarded from the same account.
// func (t *TransactionsByPriceAndNonce) Pop() {
// heap.Pop(&t.heads)
// }
27 changes: 6 additions & 21 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
// Pending block is only known by the miner
if number == rpc.PendingBlockNumber {
block := b.eth.miner.PendingBlock()
if block == nil {
return nil, errors.New("pending block is not available")
}
return block.Header(), nil
}
// Otherwise resolve and return the block
Expand Down Expand Up @@ -139,9 +136,6 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
// Pending block is only known by the miner
if number == rpc.PendingBlockNumber {
block := b.eth.miner.PendingBlock()
if block == nil {
return nil, errors.New("pending block is not available")
}
return block, nil
}
// Otherwise resolve and return the block
Expand All @@ -151,17 +145,12 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
}

if number == rpc.FinalizedBlockNumber {
// TODO - Arpit
// finalBlocknumber, err := getFinalizedBlockNumber(b.eth)
// if err != nil {
// return nil, errors.New("finalized block not found")
// }

header := b.eth.blockchain.CurrentFinalBlock()
if header == nil {
finalBlocknumber, err := getFinalizedBlockNumber(b.eth)
if err != nil {
return nil, errors.New("finalized block not found")
}
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil

return b.eth.blockchain.CurrentFinalizedBlock(finalBlocknumber), nil
}

if number == rpc.SafeBlockNumber {
Expand All @@ -170,9 +159,7 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
}

header := b.eth.blockchain.CurrentSafeBlock()
if header == nil {
return nil, errors.New("safe block not found")
}

return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}

Expand Down Expand Up @@ -369,9 +356,7 @@ func (b *EthAPIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (
}

func (b *EthAPIBackend) Stats() (runnable int, blocked int) {
// TODO - Arpit
return 0, 0
// return b.eth.txPool.Stats()
return b.eth.txPool.Stats()
}

func (b *EthAPIBackend) TxPoolContent() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction) {
Expand Down
18 changes: 8 additions & 10 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
// TODO - Check this - Arpit

// START: Bor changes
eth := &Ethereum{
config: config,
merger: consensus.NewMerger(chainDb),
Expand All @@ -175,12 +176,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
// TODO - Check this - Arpit
// if ethereum.APIBackend.allowUnprotectedTxs {
// log.Debug(" ###########", "Unprotected transactions allowed")
if eth.APIBackend.allowUnprotectedTxs {
log.Debug(" ###########", "Unprotected transactions allowed")

// config.TxPool.AllowUnprotectedTxs = true
// }
config.TxPool.AllowUnprotectedTxs = true
}

gpoParams := config.GPO
if gpoParams.Default == nil {
Expand Down Expand Up @@ -832,12 +832,10 @@ func (s *Ethereum) Stop() error {
// Close all bg processes
close(s.closeCh)

// closing consensus engine first, as miner has deps on it
s.engine.Close()
// TODO - Check this Arpit
// s.txPool.Stop()
s.txPool.Close()
s.miner.Close()
s.blockchain.Stop()
s.engine.Close()

// Clean shutdown marker as the last thing before closing db
s.shutdownTracker.Stop()
Expand Down
1 change: 0 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,6 @@ func (s *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash commo
func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
borTx := false

// TEST THIS --------------------------------- Arpit
tx, blockHash, blockNumber, index, err := s.b.GetTransaction(ctx, hash)
if err != nil {
// When the transaction doesn't exist, the RPC method should return JSON null
Expand Down
Loading

0 comments on commit feea10a

Please sign in to comment.