analysis

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Ethereum Block with some information about where it came from.

Package analysis Summary of a specific reorg

Tree of blocks, used to traverse up (from children to parents) and down (from parents to children). Reorgs start on each node with more than one child.

TreeAnalysis takes in a BlockTree and collects information about reorgs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintNodeAndChildren

func PrintNodeAndChildren(node *TreeNode, depth int)

Types

type Block

type Block struct {
	Block                 *types.Block
	Origin                BlockOrigin
	NodeUri               string
	ObservedUnixTimestamp int64

	// some helpers
	Number     uint64
	Hash       common.Hash
	ParentHash common.Hash
}

Block is an geth Block and information about where it came from

func NewBlock

func NewBlock(block *types.Block, origin BlockOrigin, nodeUri string, observedUnix int64) *Block

func (*Block) String

func (block *Block) String() string

type BlockOrigin

type BlockOrigin string
const (
	OriginSubscription BlockOrigin = "Subscription"
	OriginGetParent    BlockOrigin = "GetParent"
	OriginUncle        BlockOrigin = "Uncle"
)

type BlockTree

type BlockTree struct {
	FirstNode           *TreeNode
	LatestNodes         []*TreeNode // Nodes at latest blockheight (can be more than 1)
	NodeByHash          map[common.Hash]*TreeNode
	MainChainNodeByHash map[common.Hash]*TreeNode
}

func NewBlockTree

func NewBlockTree() *BlockTree

func (*BlockTree) AddBlock

func (t *BlockTree) AddBlock(block *Block) error

func (*BlockTree) Print

func (t *BlockTree) Print()

type Reorg

type Reorg struct {
	IsFinished bool
	SeenLive   bool

	StartBlockHeight uint64 // first block in a reorg (block number after common parent)
	EndBlockHeight   uint64 // last block in a reorg

	Chains map[common.Hash][]*Block

	Depth int

	BlocksInvolved    map[common.Hash]*Block
	MainChainHash     common.Hash
	MainChainBlocks   map[common.Hash]*Block
	NumReplacedBlocks int
	EthNodesInvolved  map[string]bool

	CommonParent         *Block
	FirstBlockAfterReorg *Block
}

func NewReorg

func NewReorg(parentNode *TreeNode) (*Reorg, error)

func (*Reorg) Id

func (r *Reorg) Id() string

func (*Reorg) MermaidSyntax

func (r *Reorg) MermaidSyntax() string

func (*Reorg) String

func (r *Reorg) String() string

type TreeAnalysis

type TreeAnalysis struct {
	Tree *BlockTree

	StartBlockHeight uint64 // first block number with siblings
	EndBlockHeight   uint64
	IsSplitOngoing   bool

	NumBlocks          int
	NumBlocksMainChain int

	Reorgs map[string]*Reorg
}

func NewTreeAnalysis

func NewTreeAnalysis(t *BlockTree) (*TreeAnalysis, error)

func (*TreeAnalysis) Print

func (a *TreeAnalysis) Print()

type TreeNode

type TreeNode struct {
	Block    *Block
	Parent   *TreeNode
	Children []*TreeNode

	IsFirst     bool
	IsMainChain bool
}

func NewTreeNode

func NewTreeNode(block *Block, parent *TreeNode) *TreeNode

func (*TreeNode) AddChild

func (tn *TreeNode) AddChild(node *TreeNode)

func (*TreeNode) String

func (tn *TreeNode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL