raft

package
v0.0.0-...-8ad0a2a Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinterRole     = etcdRaft.LEADER
	TickerMS       = 100 // Raft's ticker interval
	SnapshotPeriod = 250 // Snapshot after this many raft messages
)

Variables

View Source
var (
	BlockReward      *big.Int = new(big.Int).Mul(big.NewInt(1e+18), big.NewInt(20))
	BlockAttenuation *big.Int = big.NewInt(2500000)
)
View Source
var (
	AppliedDbKey = []byte("applied")
)
View Source
var ExtraVanity = 32 // Fixed number of extra-data prefix bytes reserved for arbitrary signer vanity

Functions

func Fatalf

func Fatalf(format string, args ...interface{})

TODO: this is just copied over from cmd/utils/cmd.go. dedupe Fatalf formats a message to standard error and exits the program. The message is also printed to standard output if standard error is redirected to a different file.

func GenUpdateRaftConfigJson

func GenUpdateRaftConfigJson(enode []byte, path string) (uint16, error)

func GetRaftConfigJson

func GetRaftConfigJson(path string) (uint16, error)

func GetRaftIdFromEnodeId

func GetRaftIdFromEnodeId(enode []byte) uint16

func GetRandomRaftIdFromEnodeId

func GetRandomRaftIdFromEnodeId(enode []byte) (uint16, error)

func NewStoppableListener

func NewStoppableListener(addr string, stopc <-chan struct{}) (*stoppableListener, error)

func ReadGenRaftConfigJson

func ReadGenRaftConfigJson(enode []byte, path string) (uint16, error)

Types

type Address

type Address struct {
	RaftId   uint16        `json:"raftId"`
	NodeId   enode.EnodeID `json:"nodeId"`
	Ip       net.IP        `json:"ip"`
	P2pPort  enr.TCP       `json:"p2pPort"`
	RaftPort enr.RaftPort  `json:"raftPort"`
}

Serializable information about a Peer. Sufficient to build `etcdRaft.Peer` or `enode.Node`. As NodeId is mainly used to derive the `ecdsa.pubkey` to build `enode.Node` it is kept as [64]byte instead of ID [32]byte used by `enode.Node`.

func BytesToAddress

func BytesToAddress(bytes []byte) *Address

func NewAddress

func NewAddress(raftId uint16, raftPort int, node *enode.Node) *Address

func (*Address) DecodeRLP

func (addr *Address) DecodeRLP(s *rlp.Stream) error

func (*Address) EncodeRLP

func (addr *Address) EncodeRLP(w io.Writer) error

func (*Address) ToBytes

func (addr *Address) ToBytes() []byte

RLP Address encoding, for transport over raft and storage in LevelDB.

type AddressTxes

type AddressTxes map[common.Address]types.Transactions

type ExtraSeal

type ExtraSeal struct {
	RaftId    []byte // RaftID of the block RaftMinter
	Signature []byte // Signature of the block RaftMinter
}

type InvalidRaftOrdering

type InvalidRaftOrdering struct {
	// Current head of the chain
	HeadBlock *types.Block

	// New block that should point to the head, but doesn't
	InvalidBlock *types.Block
}

type Peer

type Peer struct {
	Address *Address    // For raft transport
	P2pNode *enode.Node // For ethereum transport
}

A peer that we're connected to via both raft's http transport, and ethereum p2p

type Raft

type Raft struct {
	*ethash.Ethash
	// contains filtered or unexported fields
}

func New

func New(nodeKey *ecdsa.PrivateKey) *Raft

func (*Raft) Finalize

func (r *Raft) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, _ []*types.Receipt) error

func (*Raft) FinalizeAndAssemble

func (r *Raft) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
	uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

func (*Raft) SetId

func (r *Raft) SetId(raftId uint16)

type SealContext

type SealContext struct {
	InvalidRaftOrderingChan chan InvalidRaftOrdering
	SpeculativeChain        *SpeculativeChain
	ShouldMine              *channels.RingChannel
}

type SpeculativeChain

type SpeculativeChain struct {
	// contains filtered or unexported fields
}

The speculative chain represents blocks that we have minted which haven't been accepted into the chain yet, building on each other in a chain. It has three basic operations: * add new block to end * accept / remove oldest block * unwind / remove invalid blocks to the end

Additionally: * clear state when we stop minting * set the parent when we're not minting (so it's always current)

func NewSpeculativeChain

func NewSpeculativeChain() *SpeculativeChain

func (*SpeculativeChain) Accept

func (chain *SpeculativeChain) Accept(acceptedBlock *types.Block)

Accept this block, removing it from the speculative chain

func (*SpeculativeChain) Clear

func (chain *SpeculativeChain) Clear(block *types.Block)

func (*SpeculativeChain) Extend

func (chain *SpeculativeChain) Extend(block *types.Block)

Append a new speculative block

func (*SpeculativeChain) Head

func (chain *SpeculativeChain) Head() *types.Block

func (*SpeculativeChain) SetHead

func (chain *SpeculativeChain) SetHead(block *types.Block)

Set the parent of the speculative chain

Note: This is only called when not minter

func (*SpeculativeChain) UnwindFrom

func (chain *SpeculativeChain) UnwindFrom(invalidHash common.Hash, headBlock *types.Block)

Remove all blocks in the chain from the specified one until the end

func (*SpeculativeChain) WithoutProposedTxes

func (chain *SpeculativeChain) WithoutProposedTxes(txes types.Transactions) types.Transactions

func (*SpeculativeChain) WithoutProposedTxes2

func (chain *SpeculativeChain) WithoutProposedTxes2(addrTxes AddressTxes) AddressTxes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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