Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 17, 2024
1 parent 99a84da commit a86d211
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 191 deletions.
44 changes: 23 additions & 21 deletions scenarios/blob-combined/blob_combined.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"math/rand"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -94,13 +95,12 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
func (s *Scenario) Run(tester *tester.Tester) error {
s.tester = tester
txIdxCounter := uint64(0)
counterMutex := sync.Mutex{}
waitGroup := sync.WaitGroup{}
pendingCount := uint64(0)
txCount := uint64(0)
pendingCount := atomic.Int64{}
txCount := atomic.Uint64{}
startTime := time.Now()
var lastChan chan bool

s.logger.Infof("starting scenario: combined")
s.logger.Infof("starting scenario: blob-combined")

for {
txIdx := txIdxCounter
Expand All @@ -110,17 +110,13 @@ func (s *Scenario) Run(tester *tester.Tester) error {
// await pending transactions
s.pendingChan <- true
}
waitGroup.Add(1)
counterMutex.Lock()
pendingCount++
counterMutex.Unlock()
pendingCount.Add(1)
currentChan := make(chan bool, 1)

go func(txIdx uint64) {
go func(txIdx uint64, lastChan, currentChan chan bool) {
defer func() {
counterMutex.Lock()
pendingCount--
counterMutex.Unlock()
waitGroup.Done()
pendingCount.Add(-1)
currentChan <- true
}()

logger := s.logger
Expand All @@ -134,6 +130,10 @@ func (s *Scenario) Run(tester *tester.Tester) error {
if wallet != nil {
logger = logger.WithField("wallet", s.tester.GetWalletIndex(wallet.GetAddress()))
}
if lastChan != nil {
<-lastChan
close(lastChan)
}
if err != nil {
logger.Warnf("blob tx %6d.0 failed: %v", txIdx+1, err)
if s.pendingChan != nil {
Expand All @@ -142,13 +142,13 @@ func (s *Scenario) Run(tester *tester.Tester) error {
return
}

counterMutex.Lock()
txCount++
counterMutex.Unlock()
txCount.Add(1)
logger.Infof("blob tx %6d.0 sent: %v (%v sidecars)", txIdx+1, tx.Hash().String(), len(tx.BlobTxSidecar().Blobs))
}(txIdx)
}(txIdx, lastChan, currentChan)

lastChan = currentChan

count := txCount + pendingCount
count := txCount.Load() + uint64(pendingCount.Load())
if s.options.TotalCount > 0 && count >= s.options.TotalCount {
break
}
Expand All @@ -158,7 +158,8 @@ func (s *Scenario) Run(tester *tester.Tester) error {
}
}
}
waitGroup.Wait()
<-lastChan
close(lastChan)

s.logger.Infof("finished sending transactions, awaiting block inclusion...")
s.pendingWGroup.Wait()
Expand Down Expand Up @@ -279,6 +280,7 @@ func (s *Scenario) sendBlobTx(txIdx uint64, replacementIdx uint64, txNonce uint6
awaitConfirmation = false
if replacementIdx == 0 {
if s.pendingChan != nil {
time.Sleep(100 * time.Millisecond)
<-s.pendingChan
}
}
Expand Down Expand Up @@ -311,7 +313,7 @@ func (s *Scenario) sendBlobTx(txIdx uint64, replacementIdx uint64, txNonce uint6
gweiBaseFee := new(big.Int).Div(effectiveGasPrice, big.NewInt(1000000000))
gweiBlobFee := new(big.Int).Div(blobGasPrice, big.NewInt(1000000000))

s.logger.WithField("client", client.GetName()).Infof("blob tx %6d.%v confirmed in block #%v! total fee: %v gwei (base: %v, blob: %v)", txIdx+1, replacementIdx, receipt.BlockNumber.String(), gweiTotalFee, gweiBaseFee, gweiBlobFee)
s.logger.WithField("client", client.GetName()).Debugf("blob tx %6d.%v confirmed in block #%v! total fee: %v gwei (base: %v, blob: %v)", txIdx+1, replacementIdx, receipt.BlockNumber.String(), gweiTotalFee, gweiBaseFee, gweiBlobFee)
},
LogFn: func(client *txbuilder.Client, retry int, rebroadcast int, err error) {
logger := s.logger.WithField("client", client.GetName())
Expand Down
44 changes: 23 additions & 21 deletions scenarios/blob-conflicting/blob_conflicting.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"math/rand"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -90,13 +91,12 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
func (s *Scenario) Run(tester *tester.Tester) error {
s.tester = tester
txIdxCounter := uint64(0)
counterMutex := sync.Mutex{}
waitGroup := sync.WaitGroup{}
pendingCount := uint64(0)
txCount := uint64(0)
pendingCount := atomic.Int64{}
txCount := atomic.Uint64{}
startTime := time.Now()
var lastChan chan bool

s.logger.Infof("starting scenario: conflicting")
s.logger.Infof("starting scenario: blob-conflicting")

for {
txIdx := txIdxCounter
Expand All @@ -106,17 +106,13 @@ func (s *Scenario) Run(tester *tester.Tester) error {
// await pending transactions
s.pendingChan <- true
}
waitGroup.Add(1)
counterMutex.Lock()
pendingCount++
counterMutex.Unlock()
pendingCount.Add(1)
currentChan := make(chan bool, 1)

go func(txIdx uint64) {
go func(txIdx uint64, lastChan, currentChan chan bool) {
defer func() {
counterMutex.Lock()
pendingCount--
counterMutex.Unlock()
waitGroup.Done()
pendingCount.Add(-1)
currentChan <- true
}()

logger := s.logger
Expand All @@ -130,19 +126,23 @@ func (s *Scenario) Run(tester *tester.Tester) error {
if wallet != nil {
logger = logger.WithField("wallet", s.tester.GetWalletIndex(wallet.GetAddress()))
}
if lastChan != nil {
<-lastChan
close(lastChan)
}
if err != nil {
logger.Warnf("could not send blob transaction: %v", err)
<-s.pendingChan
return
}

counterMutex.Lock()
txCount++
counterMutex.Unlock()
txCount.Add(1)
logger.Infof("sent blob tx #%6d: %v (%v sidecars)", txIdx+1, tx.Hash().String(), len(tx.BlobTxSidecar().Blobs))
}(txIdx)
}(txIdx, lastChan, currentChan)

lastChan = currentChan

count := txCount + pendingCount
count := txCount.Load() + uint64(pendingCount.Load())
if s.options.TotalCount > 0 && count >= s.options.TotalCount {
break
}
Expand All @@ -152,7 +152,8 @@ func (s *Scenario) Run(tester *tester.Tester) error {
}
}
}
waitGroup.Wait()
<-lastChan
close(lastChan)

s.logger.Infof("finished sending transactions, awaiting block inclusion...")
s.pendingWGroup.Wait()
Expand Down Expand Up @@ -271,6 +272,7 @@ func (s *Scenario) sendBlobTx(txIdx uint64) (*types.Transaction, *txbuilder.Clie
OnConfirm: func(tx *types.Transaction, receipt *types.Receipt, err error) {
defer func() {
if s.pendingChan != nil {
time.Sleep(100 * time.Millisecond)
<-s.pendingChan
}
s.pendingWGroup.Done()
Expand Down Expand Up @@ -385,5 +387,5 @@ func (s *Scenario) processTxReceipt(txIdx uint64, tx *types.Transaction, receipt
gweiBaseFee := new(big.Int).Div(effectiveGasPrice, big.NewInt(1000000000))
gweiBlobFee := new(big.Int).Div(blobGasPrice, big.NewInt(1000000000))

s.logger.WithField("client", client.GetName()).Infof(" transaction %d/%v confirmed in block #%v. total fee: %v gwei (base: %v, blob: %v)", txIdx+1, txLabel, receipt.BlockNumber.String(), gweiTotalFee, gweiBaseFee, gweiBlobFee)
s.logger.WithField("client", client.GetName()).Debugf(" transaction %d/%v confirmed in block #%v. total fee: %v gwei (base: %v, blob: %v)", txIdx+1, txLabel, receipt.BlockNumber.String(), gweiTotalFee, gweiBaseFee, gweiBlobFee)
}
40 changes: 19 additions & 21 deletions scenarios/blob-replacements/blob_replacements.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"math/rand"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -94,13 +95,12 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
func (s *Scenario) Run(tester *tester.Tester) error {
s.tester = tester
txIdxCounter := uint64(0)
counterMutex := sync.Mutex{}
waitGroup := sync.WaitGroup{}
pendingCount := uint64(0)
txCount := uint64(0)
pendingCount := atomic.Int64{}
txCount := atomic.Uint64{}
startTime := time.Now()
var lastChan chan bool

s.logger.Infof("starting scenario: replacements")
s.logger.Infof("starting scenario: blob-replacements")

for {
txIdx := txIdxCounter
Expand All @@ -110,17 +110,13 @@ func (s *Scenario) Run(tester *tester.Tester) error {
// await pending transactions
s.pendingChan <- true
}
waitGroup.Add(1)
counterMutex.Lock()
pendingCount++
counterMutex.Unlock()
pendingCount.Add(1)
currentChan := make(chan bool, 1)

go func(txIdx uint64) {
go func(txIdx uint64, lastChan, currentChan chan bool) {
defer func() {
counterMutex.Lock()
pendingCount--
counterMutex.Unlock()
waitGroup.Done()
pendingCount.Add(-1)
currentChan <- true
}()

logger := s.logger
Expand All @@ -136,13 +132,13 @@ func (s *Scenario) Run(tester *tester.Tester) error {
return
}

counterMutex.Lock()
txCount++
counterMutex.Unlock()
txCount.Add(1)
logger.Infof("blob tx %6d.0 sent: %v (%v sidecars), wallet: %v, nonce: %v", txIdx+1, tx.Hash().String(), len(tx.BlobTxSidecar().Blobs), s.tester.GetWalletIndex(wallet.GetAddress()), tx.Nonce())
}(txIdx)
}(txIdx, lastChan, currentChan)

count := txCount + pendingCount
lastChan = currentChan

count := txCount.Load() + uint64(pendingCount.Load())
if s.options.TotalCount > 0 && count >= s.options.TotalCount {
break
}
Expand All @@ -152,7 +148,8 @@ func (s *Scenario) Run(tester *tester.Tester) error {
}
}
}
waitGroup.Wait()
<-lastChan
close(lastChan)

s.logger.Infof("finished sending transactions, awaiting block inclusion...")
s.pendingWGroup.Wait()
Expand Down Expand Up @@ -273,6 +270,7 @@ func (s *Scenario) sendBlobTx(txIdx uint64, replacementIdx uint64, txNonce uint6
awaitConfirmation = false
if replacementIdx == 0 {
if s.pendingChan != nil {
time.Sleep(100 * time.Millisecond)
<-s.pendingChan
}
}
Expand Down Expand Up @@ -305,7 +303,7 @@ func (s *Scenario) sendBlobTx(txIdx uint64, replacementIdx uint64, txNonce uint6
gweiBaseFee := new(big.Int).Div(effectiveGasPrice, big.NewInt(1000000000))
gweiBlobFee := new(big.Int).Div(blobGasPrice, big.NewInt(1000000000))

s.logger.WithField("client", client.GetName()).Infof("blob tx %6d.%v confirmed in block #%v! total fee: %v gwei (base: %v, blob: %v)", txIdx+1, replacementIdx, receipt.BlockNumber.String(), gweiTotalFee, gweiBaseFee, gweiBlobFee)
s.logger.WithField("client", client.GetName()).Debugf("blob tx %6d.%v confirmed in block #%v! total fee: %v gwei (base: %v, blob: %v)", txIdx+1, replacementIdx, receipt.BlockNumber.String(), gweiTotalFee, gweiBaseFee, gweiBlobFee)
},
LogFn: func(client *txbuilder.Client, retry int, rebroadcast int, err error) {
logger := s.logger.WithField("client", client.GetName())
Expand Down
Loading

0 comments on commit a86d211

Please sign in to comment.