networkMiner

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 18 Imported by: 0

README

Table of Contents

  1. Pegnet Network Coordinator
  2. The Polling Part --> Network Coordinator
  3. The PoW Part --> Network Miner
    1. Start of mining
    2. The stop of mining
  4. Other Network Mining Features
    1. Network Mining Security
  5. Running the Network Mining Setup

Pegnet Network Coordinator

I am going to assume you read the documentation on mining, and have a general understanding of how a miner works. To be brief though a miner consists of a few parts:

  1. Polling
  • The miner needs access to a factomd and pricing data sources to poll for the oracle price record (OPR) data, and submit them every block.
  1. The hashing PoW
  • Given the polling data, the miner needs to repeatly hash the opr, and when the polling indicates the block is about to close, the miner should submit the best X hashes it has collected. (this is the simple algo atm)

This means, for every miner you setup, you horizontally scale your polling. If you have 10 miners, that is a lot. So instead we split the miner into 2 parts. 1 part polling, and 1 part PoW.

The Polling Part --> Network Coordinator

What is the network coordinator?

The network coodinator is a daemon that polls factomd and price data sources and forwards the information to the network miners. The data that is sent to miners:

  • Full OPRs that contain all the price information, block height, etc
  • Factomd events (every minute and block)
    • One of these events tells the miners to stop mining for a block

The coordinator can also receive information from miners:

  • Entries that contain the OPR + nonce. The coordinator will create the commit/reveal (paying for it) and submit the entry to Factom.
  • Statistics to enable the control panel to display the miner's hashrate and some other information
  • Some extra control related information like password challenges (will be described below)

The PoW Part --> Network Miner

The network miner does not talk to a factomd, a data source, or anything else. It will ONLY talk to a coordinator, meaning you can place these behind LANs and they do not need internet access. They only need access to the network coordinator.

The network miner will listen for events to start and stop mining, submitting their best work at the end of a mining period.

Start of mining

When a network miner receives the signal to start mining, the miner will replace the Identity and coinbase payout in the OPR with their own. This means individual miners can different payout addresses, and more importantly the identity for different miners MUST be different. I repeat, the identity between miners MUST be different. If they are the same, your identical miners will hash the exact same search space, wasting hashpower.

The miners will continue to hash until the stop signal comes in

The stop of mining

When the coordinator tells the miner to stop, the miner will submit it's best X records to the coordinator. All the records will be written. In the current implementation, the network coordinator does not filter the entries that get written to the blockchain. This is a TODO.

So if you have 5 network miners, all submitting their best 3 OPRs by difficulty, then the network coordinator will submit 15 entries per block. There will be a change coming to allow a network coordinator to aggregate by payout address.

Other Network Mining Features

Network Mining Security

To ensure random network miners do not connect to your network coordinator, the coordinator and miner can enforce a basic authentication scheme. By enabling the authentication (on by default), the miner and the coordinator need to both contain the same shared secret. The coordinator then upon receiving a connection request, will issue a challenge to the miner, where the miner needs to hash the challenge along with the password, and return it. This basic challenge means the password is never relayed across a network, and packet sniffing would not allow any 3rd party to join, as the challenge changes with each connection request.

Running the Network Mining Setup

If you read the mining documentation, then you are halfway there to running a network mining setup. The configuration of a network coordinator is the exact same as a regular miner. You will need to read those docs to setup an ECaddress and orcale price locations. It will just not do the PoW mining. The additional configurations include the shared secret located in the config file, and the ability to change the listening port. To launch:

# caddr will change the port it is hosted on. This can also be changed in the config file
pegnet netcoordinator --caddr :1234

Once the netcoordinator is running, you can now run netminers to communicate with the coordinator. The configuration needed is:

  • MiningCoordinatorHost in the config or --caddr for the ip:port of the coordinator.
  • CoordinatorSecret should match the coordinator
  • UseCoordinatorAuthentication should be true
  • NumberOfMiners or --miners should not exceed your core count.
  • RecordsPerBlock or --top determines how many entries per block to submit
  • IdentityChain Make this unique PER netminer
  • FCTAddress and CoinbaseAddress should be set to an address you control
# For a 4 core machine and submit 5 entries per block
pegnet netminer --caddr localhost:1234 --miners 4 --top 5

Documentation

Index

Constants

View Source
const (
	Ping
	Pong
	FactomEvent
	GraderEvent
	ConstructedOPR
	FactomEntry
	MiningStatistics
	AddTag
	SecretChallenge
	RejectedConnection // Sever rejected client
	CoordinatorError
)
View Source
const (
	FactomdEventForward
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticationChallenge

type AuthenticationChallenge struct {
	Challenge string // Request
	Response  string // Response
}

AuthenticationChallenge is used for request + response

type ErrorMessage

type ErrorMessage struct {
	Error string
}

ErrorMessage allows us to send w/e errors we want to a client

type GobbedEntry

type GobbedEntry struct {
	ChainID string   `json:"chainid"`
	ExtIDs  [][]byte `json:"extids"`
	Content []byte   `json:"content"`
}

Idk why the factom.entry does not work

type MiningClient

type MiningClient struct {
	Host            string // Coordinator Location
	FactomDigitalID string

	Monitor  *common.FakeMonitor
	Grader   *opr.FakeGrader
	OPRMaker *mining.BlockingOPRMaker

	UpstreamStats chan *mining.GroupMinerStats
	// contains filtered or unexported fields
}

MiningClient talks to a coordinator. It receives events and trys to maintain a connection

func NewMiningClient

func NewMiningClient(config *config.Config) *MiningClient

func (*MiningClient) Connect

func (c *MiningClient) Connect() error

func (*MiningClient) ConnectionLost

func (c *MiningClient) ConnectionLost(err error)

ConnectionLost will put us into a holding pattern to reconnect

func (*MiningClient) Forwarder

func (c *MiningClient) Forwarder()

Forwarder will forward our channels to the coordinator

func (*MiningClient) Listen

func (c *MiningClient) Listen(cancel context.CancelFunc)

Listen for server events

func (*MiningClient) Listeners

func (c *MiningClient) Listeners() (common.IMonitor, opr.IGrader, mining.IOPRMaker)

func (*MiningClient) NewEntryForwarder

func (c *MiningClient) NewEntryForwarder() *mining.EntryForwarder

type MiningServer

type MiningServer struct {
	FactomMonitor common.IMonitor
	OPRGrader     opr.IGrader
	Host          string

	Server *TCPServer
	EC     *factom.ECAddress

	Stats *mining.GlobalStatTracker
	// contains filtered or unexported fields
}

MiningServer is the coordinator to emit events to anyone listening

func NewMiningServer

func NewMiningServer(config *config.Config, monitor common.IMonitor, grader opr.IGrader, stats *mining.GlobalStatTracker) *MiningServer

func (*MiningServer) Accept

func (s *MiningServer) Accept(c *TCPClient)

func (*MiningServer) Fields

func (s *MiningServer) Fields() log.Fields

func (*MiningServer) ForwardMonitorEvents

func (c *MiningServer) ForwardMonitorEvents()

ForwardMonitorEvents will forward all the events we get to anyone listening

func (*MiningServer) GetAuthenticationChallenge

func (s *MiningServer) GetAuthenticationChallenge(c *TCPClient) AuthenticationChallenge

func (*MiningServer) Listen

func (s *MiningServer) Listen()

func (*MiningServer) SendToClients

func (n *MiningServer) SendToClients(message *NetworkMessage, logger *log.Entry)

func (*MiningServer) WriteEntry

func (s *MiningServer) WriteEntry(entry *factom.Entry) error

type NetworkMessage

type NetworkMessage struct {
	NetworkCommand int
	Data           interface{}
	Version        string
}

func NewNetworkMessage

func NewNetworkMessage(cmd int, data interface{}) *NetworkMessage

type TCPClient

type TCPClient struct {
	Server *TCPServer
	// contains filtered or unexported fields
}

func NewTCPClient

func NewTCPClient(conn net.Conn, s *TCPServer) *TCPClient

func (*TCPClient) Close

func (c *TCPClient) Close() error

func (*TCPClient) Conn

func (c *TCPClient) Conn() net.Conn

func (*TCPClient) LogFields added in v0.2.1

func (c *TCPClient) LogFields() log.Fields

func (*TCPClient) SendNetworkCommand

func (c *TCPClient) SendNetworkCommand(message *NetworkMessage) error

SendNetworkCommand text message to client

type TCPServer

type TCPServer struct {
	Host string
	// contains filtered or unexported fields
}

TCPServer is heavily inspired by https://github.com/firstrow/tcp_server

func NewTCPServer

func NewTCPServer(host string) *TCPServer

Creates new tcp server instance

func (*TCPServer) Listen

func (s *TCPServer) Listen()

Listen starts network server

func (*TCPServer) OnClientConnectionClosed

func (s *TCPServer) OnClientConnectionClosed(callback func(c *TCPClient, err error))

Called right after connection closed

func (*TCPServer) OnNewClient

func (s *TCPServer) OnNewClient(callback func(c *TCPClient))

Called right after server starts listening new client

func (*TCPServer) OnNewMessage

func (s *TCPServer) OnNewMessage(callback func(c *TCPClient, message *NetworkMessage))

Called when Client receives new message

type Tag

type Tag struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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