add: updateStake when miner starts to mine new task

This commit is contained in:
bahadylbekov 2020-11-13 18:51:23 +03:00
parent d99443d9f0
commit 1ea482c379
4 changed files with 23 additions and 9 deletions

View File

@ -16,6 +16,7 @@ import (
type Miner struct {
address peer.ID
ethAddress common.Address
api MinerAPI
mutex sync.Mutex
}
@ -81,7 +82,7 @@ func (m *MinerBase) UpdateStake(c *ethclient.EthereumClient, miner common.Addres
// Start, Stop mining functions
func (m *Miner) MineTask(ctx context.Context, base *MiningBase, mb *MinerBase) (*types.DioneTask, error) {
func (m *Miner) MineTask(ctx context.Context, base *MiningBase, mb *MinerBase, ethClient *ethclient.EthereumClient) (*types.DioneTask, error) {
round := base.epoch + base.nullRounds + 1
logrus.Debug("attempting to mine the task at epoch: ", round)
@ -93,6 +94,10 @@ func (m *Miner) MineTask(ctx context.Context, base *MiningBase, mb *MinerBase) (
rbase = bvals[len(bvals)-1]
}
if err := mb.UpdateStake(ethClient, m.ethAddress); err != nil {
return nil, xerrors.Errorf("failed to update miner stake: %w", err)
}
ticket, err := m.computeTicket(ctx, &rbase, base, mb)
if err != nil {
return nil, xerrors.Errorf("scratching ticket failed: %w", err)

1
go.mod
View File

@ -23,6 +23,7 @@ require (
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/snappy v0.0.2-0.20190904063534-ff6b7dc882cf // indirect
github.com/google/gopacket v1.1.18 // indirect
github.com/google/logger v1.1.0
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
github.com/ipfs/go-datastore v0.4.5 // indirect
github.com/ipfs/go-ds-badger2 v0.1.1-0.20200708190120-187fc06f714e // indirect

2
go.sum
View File

@ -286,6 +286,8 @@ github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbB
github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
github.com/google/gopacket v1.1.18 h1:lum7VRA9kdlvBi7/v2p7/zcbkduHaCH/SVVyurs7OpY=
github.com/google/gopacket v1.1.18/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM=
github.com/google/logger v1.1.0 h1:saB74Etb4EAJNH3z74CVbCKk75hld/8T0CsXKetWCwM=
github.com/google/logger v1.1.0/go.mod h1:w7O8nrRr0xufejBlQMI83MXqRusvREoJdaAxV+CoAB4=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=

View File

@ -5,14 +5,15 @@ import (
"crypto/rand"
"flag"
"fmt"
pex "github.com/Secured-Finance/go-libp2p-pex"
"time"
pex "github.com/Secured-Finance/go-libp2p-pex"
"github.com/Secured-Finance/dione/config"
"github.com/Secured-Finance/dione/consensus"
"github.com/Secured-Finance/dione/ethclient"
"github.com/Secured-Finance/dione/pb"
"github.com/Secured-Finance/dione/rpc"
"github.com/Secured-Finance/dione/ethclient"
"github.com/libp2p/go-libp2p"
crypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
@ -21,7 +22,7 @@ import (
)
const (
DefaultPEXUpdateTime = 1*time.Minute
DefaultPEXUpdateTime = 1 * time.Minute
)
type Node struct {
@ -52,7 +53,9 @@ func NewNode(configPath string) (*Node, error) {
func (n *Node) setupNode(ctx context.Context, prvKey crypto.PrivKey, pexDiscoveryUpdateTime time.Duration) {
n.setupLibp2pHost(context.TODO(), prvKey, pexDiscoveryUpdateTime)
//n.setupEthereumClient()
if err := n.setupEthereumClient(); err != nil {
logrus.Fatal("Can't set up an ethereum client, exiting... ", err)
}
//n.setupFilecoinClient()
n.setupPubsub()
n.setupConsensusManager(n.Config.ConsensusMaxFaultNodes)
@ -116,6 +119,9 @@ func (n *Node) setupLibp2pHost(ctx context.Context, privateKey crypto.PrivKey, p
}
discovery, err := pex.NewPEXDiscovery(host, bootstrapMaddrs, pexDiscoveryUpdateTime)
if err != nil {
logrus.Fatal("Can't set up PEX discovery protocol, exiting... ", err)
}
logrus.Info("Announcing ourselves...")
_, err = discovery.Advertise(context.TODO(), n.Config.Rendezvous)