Skip to content

Commit 891bbad

Browse files
params: implement String() method for ChainConfig (#32766)
Fixes issue #32762 where ChainConfig logging displays pointer addresses instead of actual timestamp values for fork activation times. Before: ShanghaiTime:(*uint64)(0xc000373fb0), CancunTime:(*uint64)(0xc000373fb8) After: ShanghaiTime: 1681338455, CancunTime: 1710338135, VerkleTime: nil The String() method properly dereferences timestamp pointers and handles nil values for unset fork times, making logs more readable and useful for debugging chain configuration issues. --------- Co-authored-by: rjl493456442 <[email protected]>
1 parent 1cfe624 commit 891bbad

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

params/config.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,96 @@ func (c CliqueConfig) String() string {
504504
return fmt.Sprintf("clique(period: %d, epoch: %d)", c.Period, c.Epoch)
505505
}
506506

507+
// String implements the fmt.Stringer interface, returning a string representation
508+
// of ChainConfig.
509+
func (c *ChainConfig) String() string {
510+
result := fmt.Sprintf("ChainConfig{ChainID: %v", c.ChainID)
511+
512+
// Add block-based forks
513+
if c.HomesteadBlock != nil {
514+
result += fmt.Sprintf(", HomesteadBlock: %v", c.HomesteadBlock)
515+
}
516+
if c.DAOForkBlock != nil {
517+
result += fmt.Sprintf(", DAOForkBlock: %v", c.DAOForkBlock)
518+
}
519+
if c.EIP150Block != nil {
520+
result += fmt.Sprintf(", EIP150Block: %v", c.EIP150Block)
521+
}
522+
if c.EIP155Block != nil {
523+
result += fmt.Sprintf(", EIP155Block: %v", c.EIP155Block)
524+
}
525+
if c.EIP158Block != nil {
526+
result += fmt.Sprintf(", EIP158Block: %v", c.EIP158Block)
527+
}
528+
if c.ByzantiumBlock != nil {
529+
result += fmt.Sprintf(", ByzantiumBlock: %v", c.ByzantiumBlock)
530+
}
531+
if c.ConstantinopleBlock != nil {
532+
result += fmt.Sprintf(", ConstantinopleBlock: %v", c.ConstantinopleBlock)
533+
}
534+
if c.PetersburgBlock != nil {
535+
result += fmt.Sprintf(", PetersburgBlock: %v", c.PetersburgBlock)
536+
}
537+
if c.IstanbulBlock != nil {
538+
result += fmt.Sprintf(", IstanbulBlock: %v", c.IstanbulBlock)
539+
}
540+
if c.MuirGlacierBlock != nil {
541+
result += fmt.Sprintf(", MuirGlacierBlock: %v", c.MuirGlacierBlock)
542+
}
543+
if c.BerlinBlock != nil {
544+
result += fmt.Sprintf(", BerlinBlock: %v", c.BerlinBlock)
545+
}
546+
if c.LondonBlock != nil {
547+
result += fmt.Sprintf(", LondonBlock: %v", c.LondonBlock)
548+
}
549+
if c.ArrowGlacierBlock != nil {
550+
result += fmt.Sprintf(", ArrowGlacierBlock: %v", c.ArrowGlacierBlock)
551+
}
552+
if c.GrayGlacierBlock != nil {
553+
result += fmt.Sprintf(", GrayGlacierBlock: %v", c.GrayGlacierBlock)
554+
}
555+
if c.MergeNetsplitBlock != nil {
556+
result += fmt.Sprintf(", MergeNetsplitBlock: %v", c.MergeNetsplitBlock)
557+
}
558+
559+
// Add timestamp-based forks
560+
if c.ShanghaiTime != nil {
561+
result += fmt.Sprintf(", ShanghaiTime: %v", *c.ShanghaiTime)
562+
}
563+
if c.CancunTime != nil {
564+
result += fmt.Sprintf(", CancunTime: %v", *c.CancunTime)
565+
}
566+
if c.PragueTime != nil {
567+
result += fmt.Sprintf(", PragueTime: %v", *c.PragueTime)
568+
}
569+
if c.OsakaTime != nil {
570+
result += fmt.Sprintf(", OsakaTime: %v", *c.OsakaTime)
571+
}
572+
if c.BPO1Time != nil {
573+
result += fmt.Sprintf(", BPO1Time: %v", *c.BPO1Time)
574+
}
575+
if c.BPO2Time != nil {
576+
result += fmt.Sprintf(", BPO2Time: %v", *c.BPO2Time)
577+
}
578+
if c.BPO3Time != nil {
579+
result += fmt.Sprintf(", BPO3Time: %v", *c.BPO3Time)
580+
}
581+
if c.BPO4Time != nil {
582+
result += fmt.Sprintf(", BPO4Time: %v", *c.BPO4Time)
583+
}
584+
if c.BPO5Time != nil {
585+
result += fmt.Sprintf(", BPO5Time: %v", *c.BPO5Time)
586+
}
587+
if c.AmsterdamTime != nil {
588+
result += fmt.Sprintf(", AmsterdamTime: %v", *c.AmsterdamTime)
589+
}
590+
if c.VerkleTime != nil {
591+
result += fmt.Sprintf(", VerkleTime: %v", *c.VerkleTime)
592+
}
593+
result += "}"
594+
return result
595+
}
596+
507597
// Description returns a human-readable description of ChainConfig.
508598
func (c *ChainConfig) Description() string {
509599
var banner string

0 commit comments

Comments
 (0)