Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add node id to record #1

Open
wants to merge 1 commit into
base: Experiment-1-Latency-Check
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"math/big"
"os"
"sync"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion experiment-1/utils/uitls.go → experiment-1/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}

Expand Down