networking

package
v0.0.0-...-214c9eb Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBlockPeer = 200
)

Maximum amount of blocks downloaded by one node at once

Variables

View Source
var ReceiptBurned = make(map[string]bool)

TODO put ReceiptBurned in a file

Functions

func CreateVote

func CreateVote(sVote, tVote []byte, hsVote, htVote uint64, w *wallet.Wallet) protobufs.CasperVote

CreateVote : Create a vote based on casper Vote struct CasperVote: - Source -> hash of the source block - Target -> hash of any descendent of s - SourceHeight -> height of s - TargetHeight -> height of t - R, S -> signature of <s, t, h(s), h(t)> with validator private key

func GenerateMerkleProof

func GenerateMerkleProof(receipts []*protobufs.Receipt, indexProof int, transaction *protobufs.Transaction) []byte

func GetPeerList

func GetPeerList(network string) ([]string, error)

GetPeerList returns other nodes in the network

func IsJustified

func IsJustified(currentCheckpoint uint64, index uint64) bool

IsJustified : A block is justified if is the root or if it's between 2 checkpoint

func IsVoteValid

func IsVoteValid(b *blockchain.Blockchain, sourceHash, targetHash []byte, TargetHeight uint64) bool

IsVoteValid check if s is an ancestor of t in the chain

func MakeSpecificRequest

func MakeSpecificRequest(w *wallet.Wallet, shard uint32, dataRequest []byte, t network.Request_MessageTypes, c *client, shardAddress uint32) error

func SendTransaction

func SendTransaction(senderWallet *wallet.Wallet, recipient, fname string, amount, gas uint64, cdata []byte, ccreation bool, shardAddress uint32) error

SendTransaction generates a transaction and broadcasts it

func TraverseNat

func TraverseNat(port uint16, desc string) (string, error)

TraverseNat opens the port passed as an arguemnt and returns ip:port in a string. Required manaually closing port

Types

type ConnectionStore

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

ConnectionStore handles peer messaging

func StartServer

func StartServer(port, network string, shardsChain map[uint32]*blockchain.Blockchain, beaconChain *blockchain.BeaconChain, idn *wallet.Wallet) (*ConnectionStore, error)

StartServer creates a new ConnectionStore, which handles network peers

func (*ConnectionStore) AddGenesisToQueue

func (cs *ConnectionStore) AddGenesisToQueue(block *protoBlockchain.Block, shard uint32)

func (*ConnectionStore) AddInterest

func (cs *ConnectionStore) AddInterest(key string)

AddInterest adds an interest, this is used as a filter to have more efficient broadcasts and avoid sending everything to everyone

func (*ConnectionStore) AddVote

func (cs *ConnectionStore) AddVote(vote *protobufs.CasperVote, shard uint32) error

AddVote add a vote in receivedVotes and put it on the db

func (*ConnectionStore) CheckMerkleProof

func (cs *ConnectionStore) CheckMerkleProof(merkleProof *protobufs.MerkleProof) (bool, error)

func (*ConnectionStore) CheckShard

func (cs *ConnectionStore) CheckShard(shard uint32) bool

CheckShard check if the message arrived is from your interests (shards)

func (*ConnectionStore) CheckpointAgreement

func (cs *ConnectionStore) CheckpointAgreement(SourceHeight, TargetHeight uint64, currentShard uint32) bool

CheckpointAgreement : Every checkpoint there should be an agreement of 2/3 of the validators

func (*ConnectionStore) Connect

func (cs *ConnectionStore) Connect(ip string) error

Connect connects to a server and adds it to the connectionStore

func (*ConnectionStore) FindPeers

func (cs *ConnectionStore) FindPeers() error

FindPeers tries to find all peers for the selected network

func (*ConnectionStore) GetCasperVote

func (cs *ConnectionStore) GetCasperVote(index int, shard uint32) (protobufs.CasperVote, error)

GetCasperVote get a casper vote inside CasperVotesDb

func (*ConnectionStore) ImportBlock

func (cs *ConnectionStore) ImportBlock(block *protobufs.Block, shard uint32) error

ImportBlock imports a block into the blockchain and checks if it's valid This should be called on blocks that are finalized by PoS

func (*ConnectionStore) Loop

func (cs *ConnectionStore) Loop()

Loop start ValidatorLoop for every interest

func (*ConnectionStore) MakeEnvelopeBroadcast

func (cs *ConnectionStore) MakeEnvelopeBroadcast(dataBroadcast []byte, typeBroadcast network.Broadcast_BroadcastType, shardAddress uint32, shardEnvelope uint32)

func (*ConnectionStore) RemoveInterest

func (cs *ConnectionStore) RemoveInterest(key string)

func (*ConnectionStore) SaveBlock

func (cs *ConnectionStore) SaveBlock(block *protobufs.Block, shard uint32) error

SaveBlock saves an unvalidated block into the blockchain to be used with Casper

func (*ConnectionStore) StartPeerServer

func (cs *ConnectionStore) StartPeerServer()

StartPeerServer creates an HTTP server that replies with known peers

func (*ConnectionStore) UpdateChain

func (cs *ConnectionStore) UpdateChain(nextShard uint32, oldShard string) error

UpdateChain asks all connected nodes for their chain lenght, if any of them has a chain longer than the current one it will import

func (*ConnectionStore) ValidatorLoop

func (cs *ConnectionStore) ValidatorLoop(currentShard uint32)

ValidatorLoop updates the current expected validator and generates a block if the validator has the same identity as the node generates a block

func (*ConnectionStore) VerifyProof

func (cs *ConnectionStore) VerifyProof(mp *protobufs.MerkleProof, shard uint32) bool

Jump to

Keyboard shortcuts

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