minemaster

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: LGPL-3.0 Imports: 16 Imported by: 0

README

Minemaster

module analysis

image

  1. Once the instance of MasterServer, server receives work submitted by localConnector message via ReceiveMsg, it verifies the work difficulty. If this is a valid work, server submits the work by s.onSubmitBlock(w). onSubmitBlock gets the current block and seals it, then passes the sealed block to workManager.

  2. A default workManager is provided. Each masterServer has only one workManager to manage all the workers' works. Each worker corresponds to one workerPerformance instance. Different master could utilize different performance metrics/indicator by modifying their workerPerformance. Also, among the same master/workManager, different workerPerformance could by applied to distinct workers.

  3. The default instance of workManager, defaultWorkManager receives the newly sealed block, it updates the performance of the specific worker by calling manager.performance[workerAddress].updatePerformance().

  4. defaultPerformance provides a simple performance indicator based on how many blocks a worker has worked out. It increments the block count blocksMined, every time .updatePerformance() is called.

  5. Performance is a reference for reward distribution. Reward distribution may vary for different performance metrics and reward distribution policies. A default distribution policy is given, which simply linear to the performance. Note that, reward distribution is independent of how performance is calculated, it simply divide the coibase reward according to the given performance. Here, we provided a fault distribution method, which equally distributes the coinbase based on workers' performance.

Design Problem

  • It is easy for us to keep record of how much work the workers have done. But it is difficult to actually work out their reward. Since the reward is unknown unless the previous mined block is verified by verifiers, there is no way to determine reward distribution before Minemaster actually receives coinbase.

  • If the master decides to pay salary to workers constantly regardless of work submitted or how long they have join the pool, it should be straightforward to distribute reward by performance.

Conclusion

  • It si enough to provide performance indicator and reward distribution template for Minemasters, since it is not stated in the requirement documents.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeMineMaster

func MakeMineMaster(config MineConfig) (Master, MasterServer)

context must have coinbaseAddress common.Address, workBuilder workBuilder, blockBuilder blockBuilder, blockSubmitter blockSubmitter) (Master, MasterServer make a mine master

Types

type BlockBroadcaster

type BlockBroadcaster interface {
	BroadcastMinedBlock(block model.AbstractBlock)
}

type BlockBuilder

type BlockBuilder interface {
	BuildWaitPackBlock(coinbaseAddr common.Address) model.AbstractBlock
}

type Master

type Master interface {
	Start()
	Stop()
	CurrentCoinbaseAddress() common.Address
	SetCoinbaseAddress(addr common.Address)
	OnNewBlock(block model.AbstractBlock)
	Workers() map[WorkerId]WorkerForMaster

	GetReward(address common.Address) *big.Int
	GetPerformance(address common.Address) uint64

	// whether the mining is ongoing
	Mining() bool
	// cur mine block tx count
	MineTxCount() int

	SpendableMaster
}

type MasterServer

type MasterServer interface {
	RegisterWorker(worker WorkerForMaster)
	UnRegisterWorker(workerId WorkerId)
	ReceiveMsg(workerID WorkerId, code uint64, msg interface{})
	// for p2p msg
	OnNewMsg(msg p2p.Msg, p chain_communication.PmAbstractPeer) error
	// only for worker, do nothing
	SetMineMasterPeer(peer chain_communication.PmAbstractPeer)
}

type MineConfig

type MineConfig struct {
	CoinbaseAddress  *atomic.Value
	BlockBuilder     BlockBuilder
	BlockBroadcaster BlockBroadcaster
}

func (*MineConfig) GetCoinbaseAddr

func (conf *MineConfig) GetCoinbaseAddr() (result common.Address)

type SpendableMaster

type SpendableMaster interface {
	RetrieveReward(address common.Address)
}

type WorkerForMaster

type WorkerForMaster interface {
	Start()
	Stop()
	GetId() WorkerId

	SendNewWork(msgCode int, work minemsg.Work)

	SetCoinbase(coinbase common.Address)
	CurrentCoinbaseAddress() common.Address
}

type WorkerId

type WorkerId string

Jump to

Keyboard shortcuts

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