From de92cf4fda871b8d5c9392d0d59331278917f2c2 Mon Sep 17 00:00:00 2001 From: "V.O.T" Date: Wed, 7 Feb 2024 16:06:37 +0700 Subject: [PATCH] feat: add node id to record --- core/txpool/txpool.go | 8 +++++++- experiment-1/utils/{uitls.go => utils.go} | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) rename experiment-1/utils/{uitls.go => utils.go} (85%) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index b98f698a7338..bc70d93c82d3 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "math/big" + "os" "sync" "github.com/ethereum/go-ethereum/common" @@ -319,10 +320,15 @@ func (p *TxPool) Add(txs []*types.Transaction, local bool, sync bool) []error { txsets := make([][]*types.Transaction, len(p.subpools)) splits := make([]int, len(txs)) + nodeId := os.Getenv("GETH_NODEKEY") + if nodeId == "" { + log.Error("Environment variable GETH_NODEKEY is not set") + } + if local { for _, tx := range txs { // Use the RecordTransaction function from the utils package - err := utils.RecordTransaction(tx, "../../data/transactionLogFile.log") + err := utils.RecordTransaction(tx, nodeId, "../../data/transactionLogFile.log") if err != nil { log.Error("Failed to record transaction", "err", err) } else { diff --git a/experiment-1/utils/uitls.go b/experiment-1/utils/utils.go similarity index 85% rename from experiment-1/utils/uitls.go rename to experiment-1/utils/utils.go index c8639ef5e1b5..a08797f490c9 100644 --- a/experiment-1/utils/uitls.go +++ b/experiment-1/utils/utils.go @@ -11,13 +11,15 @@ import ( // TransactionLog represents the structure of the log to be saved type TransactionLog struct { Hash string `json:"hash"` + NodeId string `json:"node_id"` Timestamp time.Time `json:"timestamp"` } -func RecordTransaction(tx *types.Transaction, filename string) error { +func RecordTransaction(tx *types.Transaction, nodeId string, filename string) error { // Prepare the data to be logged data := TransactionLog{ Hash: tx.Hash().Hex(), + NodeId: nodeId, Timestamp: time.Now(), }