Skip to content

Commit

Permalink
Remove unused PooledTransactionsPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Aug 23, 2023
1 parent 7f7a11e commit b0da782
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 135 deletions.
41 changes: 6 additions & 35 deletions cmd/hack/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (

"github.com/RoaringBitmap/roaring/roaring64"
"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/common/length"
Expand All @@ -30,12 +33,6 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/temporal/historyv2"
"github.com/ledgerwatch/erigon-lib/recsplit"
"github.com/ledgerwatch/erigon-lib/recsplit/eliasfano32"
librlp "github.com/ledgerwatch/erigon-lib/rlp"
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"

hackdb "github.com/ledgerwatch/erigon/cmd/hack/db"
"github.com/ledgerwatch/erigon/cmd/hack/flow"
Expand All @@ -45,6 +42,7 @@ import (
"github.com/ledgerwatch/erigon/common/paths"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/rawdb/blockio"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
Expand All @@ -56,6 +54,8 @@ import (
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/logging"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks"
)

var (
Expand Down Expand Up @@ -1356,33 +1356,6 @@ func dumpState(chaindata string) error {
return nil
}

type NewPooledTransactionHashesPacket68 struct {
Types []byte
Sizes []uint32
Hashes []libcommon.Hash
}

func rlptest() error {
var p = NewPooledTransactionHashesPacket68{
Types: []byte{44, 200},
Sizes: []uint32{56, 57680},
Hashes: []libcommon.Hash{{}, {}},
}
b, err := rlp.EncodeToBytes(&p)
if err != nil {
return err
}
fmt.Printf("%x\n", b)
var hashes []byte
for _, h := range p.Hashes {
hashes = append(hashes, h[:]...)
}
b = make([]byte, librlp.AnnouncementsLen(p.Types, p.Sizes, hashes))
l := librlp.EncodeAnnouncements(p.Types, p.Sizes, hashes, b)
fmt.Printf("%x\n%d %d\n", b, len(b), l)
return nil
}

func main() {
debug.RaiseFdLimit()
flag.Parse()
Expand Down Expand Up @@ -1514,8 +1487,6 @@ func main() {
err = readSeg(*chaindata)
case "dumpState":
err = dumpState(*chaindata)
case "rlptest":
err = rlptest()
case "readAccountAtVersion":
err = readAccountAtVersion(*chaindata, *account, uint64(*block))
}
Expand Down
86 changes: 0 additions & 86 deletions eth/protocols/eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,83 +487,6 @@ type ReceiptsRLPPacket66 struct {
ReceiptsRLPPacket
}

// NewPooledTransactionHashesPacket represents a transaction announcement packet.
type NewPooledTransactionHashesPacket []libcommon.Hash

// GetPooledTransactionsPacket represents a transaction query.
type GetPooledTransactionsPacket []libcommon.Hash

// PooledTransactionsPacket is the network packet for transaction distribution.
type PooledTransactionsPacket []types.Transaction

func (ptp PooledTransactionsPacket) EncodeRLP(w io.Writer) error {
encodingSize := 0
// size of Transactions
encodingSize++
var txsLen int
for _, tx := range ptp {
txsLen++
var txLen int
switch t := tx.(type) {
case *types.LegacyTx:
txLen = t.EncodingSize()
case *types.AccessListTx:
txLen = t.EncodingSize()
case *types.DynamicFeeTransaction:
txLen = t.EncodingSize()
}
if txLen >= 56 {
txsLen += libcommon.BitLenToByteLen(bits.Len(uint(txLen)))
}
txsLen += txLen
}
if txsLen >= 56 {
encodingSize += libcommon.BitLenToByteLen(bits.Len(uint(txsLen)))
}
encodingSize += txsLen
// encode Transactions
var b [33]byte
if err := types.EncodeStructSizePrefix(encodingSize, w, b[:]); err != nil {
return err
}
for _, tx := range ptp {
switch t := tx.(type) {
case *types.LegacyTx:
if err := t.EncodeRLP(w); err != nil {
return err
}
case *types.AccessListTx:
if err := t.EncodeRLP(w); err != nil {
return err
}
case *types.DynamicFeeTransaction:
if err := t.EncodeRLP(w); err != nil {
return err
}
}
}
return nil
}

func (ptp *PooledTransactionsPacket) DecodeRLP(s *rlp.Stream) error {
_, err := s.List()
if err != nil {
return err
}
var tx types.Transaction
for tx, err = types.DecodeRLPTransaction(s); err == nil; tx, err = types.DecodeRLPTransaction(s) {
*ptp = append(*ptp, tx)
}
if !errors.Is(err, rlp.EOL) {
return err
}
return s.ListEnd()
}

// PooledTransactionsPacket is the network packet for transaction distribution, used
// in the cases we already have them in rlp-encoded form
type PooledTransactionsRLPPacket []rlp.RawValue

func (*StatusPacket) Name() string { return "Status" }
func (*StatusPacket) Kind() byte { return StatusMsg }

Expand Down Expand Up @@ -599,12 +522,3 @@ func (*GetReceiptsPacket) Kind() byte { return GetReceiptsMsg }

func (*ReceiptsPacket) Name() string { return "Receipts" }
func (*ReceiptsPacket) Kind() byte { return ReceiptsMsg }

func (*NewPooledTransactionHashesPacket) Name() string { return "NewPooledTransactionHashes" }
func (*NewPooledTransactionHashesPacket) Kind() byte { return NewPooledTransactionHashesMsg }

func (*GetPooledTransactionsPacket) Name() string { return "GetPooledTransactions" }
func (*GetPooledTransactionsPacket) Kind() byte { return GetPooledTransactionsMsg }

func (*PooledTransactionsPacket) Name() string { return "PooledTransactions" }
func (*PooledTransactionsPacket) Kind() byte { return PooledTransactionsMsg }
Loading

0 comments on commit b0da782

Please sign in to comment.