diff --git a/beacon/beacon.go b/beacon/beacon.go index 5852a3f..1589a51 100644 --- a/beacon/beacon.go +++ b/beacon/beacon.go @@ -135,7 +135,7 @@ func BeaconEntriesForTask(ctx context.Context, beaconNetworks BeaconNetworks) ([ } out[1] = res.Entry - logrus.Debug("fetching beacon entries", "took", lib.Clock.Since(start), "numEntries", len(out)) + logrus.Debugf("fetching beacon entries: took %v, count of entries: %v", lib.Clock.Since(start), len(out)) //reverse(out) return out, nil } diff --git a/consensus/commit_pool.go b/consensus/commit_pool.go deleted file mode 100644 index 54a41ea..0000000 --- a/consensus/commit_pool.go +++ /dev/null @@ -1,73 +0,0 @@ -package consensus - -import ( - "sync" - - types2 "github.com/Secured-Finance/dione/consensus/types" - "github.com/sirupsen/logrus" -) - -type CommitPool struct { - mut sync.RWMutex - commitMsgs map[string][]*types2.Message -} - -func NewCommitPool() *CommitPool { - return &CommitPool{ - commitMsgs: map[string][]*types2.Message{}, - } -} - -func (cp *CommitPool) CreateCommit(prepareMsg *types2.Message, privateKey []byte) (*types2.Message, error) { - var message types2.Message - message.Type = types2.MessageTypeCommit - newCMsg := prepareMsg.Payload - message.Payload = newCMsg - return &message, nil -} - -func (cp *CommitPool) IsExistingCommit(commitMsg *types2.Message) bool { - cp.mut.RLock() - defer cp.mut.RUnlock() - - consensusMessage := commitMsg.Payload - var exists bool - for _, v := range cp.commitMsgs[consensusMessage.Task.ConsensusID] { - if v.From == commitMsg.From { - exists = true - } - } - return exists -} - -func (cp *CommitPool) IsValidCommit(commit *types2.Message) bool { - consensusMsg := commit.Payload - err := verifyTaskSignature(consensusMsg) - if err != nil { - logrus.Errorf("failed to verify task signature: %v", err) - return false - } - return true -} - -func (cp *CommitPool) AddCommit(commit *types2.Message) { - cp.mut.Lock() - defer cp.mut.Unlock() - - consensusID := commit.Payload.Task.ConsensusID - if _, ok := cp.commitMsgs[consensusID]; !ok { - cp.commitMsgs[consensusID] = []*types2.Message{} - } - - cp.commitMsgs[consensusID] = append(cp.commitMsgs[consensusID], commit) -} - -func (cp *CommitPool) CommitSize(consensusID string) int { - cp.mut.RLock() - defer cp.mut.RUnlock() - - if v, ok := cp.commitMsgs[consensusID]; ok { - return len(v) - } - return 0 -} diff --git a/consensus/consensus.go b/consensus/consensus.go index 1bf54f8..43ca535 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -6,8 +6,6 @@ import ( "github.com/Secured-Finance/dione/cache" - "github.com/Secured-Finance/dione/contracts/dioneOracle" - "github.com/Secured-Finance/dione/consensus/types" "github.com/Secured-Finance/dione/ethclient" @@ -21,9 +19,8 @@ type PBFTConsensusManager struct { psb *pubsub.PubSubRouter minApprovals int privKey []byte - prePreparePool *PrePreparePool - preparePool *PreparePool - commitPool *CommitPool + msgLog *MessageLog + validator *ConsensusValidator consensusMap map[string]*Consensus ethereumClient *ethclient.EthereumClient miner *Miner @@ -41,9 +38,8 @@ func NewPBFTConsensusManager(psb *pubsub.PubSubRouter, minApprovals int, privKey pcm := &PBFTConsensusManager{} pcm.psb = psb pcm.miner = miner - pcm.prePreparePool = NewPrePreparePool(miner, evc) - pcm.preparePool = NewPreparePool() - pcm.commitPool = NewCommitPool() + pcm.validator = NewConsensusValidator(evc, miner) + pcm.msgLog = NewMessageLog() pcm.minApprovals = minApprovals pcm.privKey = privKey pcm.ethereumClient = ethereumClient @@ -55,14 +51,10 @@ func NewPBFTConsensusManager(psb *pubsub.PubSubRouter, minApprovals int, privKey return pcm } -func (pcm *PBFTConsensusManager) Propose(task types2.DioneTask, requestEvent *dioneOracle.DioneOracleNewOracleRequest) error { +func (pcm *PBFTConsensusManager) Propose(task types2.DioneTask) error { pcm.createConsensusInfo(&task, true) - prePrepareMsg, err := pcm.prePreparePool.CreatePrePrepare( - &task, - requestEvent.ReqID.String(), - pcm.privKey, - ) + prePrepareMsg, err := CreatePrePrepareWithTaskSignature(&task, pcm.privKey) if err != nil { return err } @@ -74,66 +66,66 @@ func (pcm *PBFTConsensusManager) handlePrePrepare(message *types.Message) { if message.Payload.Task.Miner == pcm.miner.address { return } - if pcm.prePreparePool.IsExistingPrePrepare(message) { + if pcm.msgLog.Exists(*message) { return } - if !pcm.prePreparePool.IsValidPrePrepare(message) { + if !pcm.validator.Valid(*message) { logrus.Warn("received invalid pre_prepare msg, dropping...") return } - pcm.prePreparePool.AddPrePrepare(message) + pcm.msgLog.AddMessage(*message) err := pcm.psb.BroadcastToServiceTopic(message) if err != nil { logrus.Errorf(err.Error()) return } - prepareMsg, err := pcm.preparePool.CreatePrepare(message, pcm.privKey) + prepareMsg, err := NewMessage(message, types.MessageTypePrepare) if err != nil { logrus.Errorf("failed to create prepare message: %w", err) } pcm.createConsensusInfo(&message.Payload.Task, false) - pcm.psb.BroadcastToServiceTopic(prepareMsg) + pcm.psb.BroadcastToServiceTopic(&prepareMsg) } func (pcm *PBFTConsensusManager) handlePrepare(message *types.Message) { - if pcm.preparePool.IsExistingPrepare(message) { + if pcm.msgLog.Exists(*message) { return } - if !pcm.preparePool.IsValidPrepare(message) { + if !pcm.validator.Valid(*message) { logrus.Warn("received invalid prepare msg, dropping...") return } - pcm.preparePool.AddPrepare(message) + pcm.msgLog.AddMessage(*message) err := pcm.psb.BroadcastToServiceTopic(message) if err != nil { logrus.Errorf(err.Error()) return } - if pcm.preparePool.PreparePoolSize(message.Payload.Task.ConsensusID) >= pcm.minApprovals { - commitMsg, err := pcm.commitPool.CreateCommit(message, pcm.privKey) + if len(pcm.msgLog.GetMessagesByTypeAndConsensusID(types.MessageTypePrepare, message.Payload.Task.ConsensusID)) >= pcm.minApprovals { + commitMsg, err := NewMessage(message, types.MessageTypeCommit) if err != nil { logrus.Errorf("failed to create commit message: %w", err) } - pcm.psb.BroadcastToServiceTopic(commitMsg) + pcm.psb.BroadcastToServiceTopic(&commitMsg) } } func (pcm *PBFTConsensusManager) handleCommit(message *types.Message) { - if pcm.commitPool.IsExistingCommit(message) { + if pcm.msgLog.Exists(*message) { return } - if !pcm.commitPool.IsValidCommit(message) { + if !pcm.validator.Valid(*message) { logrus.Warn("received invalid commit msg, dropping...") return } - pcm.commitPool.AddCommit(message) + pcm.msgLog.AddMessage(*message) err := pcm.psb.BroadcastToServiceTopic(message) if err != nil { logrus.Errorf(err.Error()) @@ -141,7 +133,7 @@ func (pcm *PBFTConsensusManager) handleCommit(message *types.Message) { } consensusMsg := message.Payload - if pcm.commitPool.CommitSize(consensusMsg.Task.ConsensusID) >= pcm.minApprovals { + if len(pcm.msgLog.GetMessagesByTypeAndConsensusID(types.MessageTypeCommit, message.Payload.Task.ConsensusID)) >= pcm.minApprovals { info := pcm.GetConsensusInfo(consensusMsg.Task.ConsensusID) if info == nil { logrus.Debugf("consensus doesn't exist in our consensus map - skipping...") diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go deleted file mode 100644 index 55af778..0000000 --- a/consensus/consensus_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package consensus - -import ( - crand "crypto/rand" - "fmt" - "math/rand" - "testing" - "time" - - "github.com/Secured-Finance/dione/config" - "github.com/Secured-Finance/dione/node" - crypto "github.com/libp2p/go-libp2p-crypto" - "github.com/sirupsen/logrus" -) - -func TestConsensus(t *testing.T) { - rand.Seed(time.Now().UnixNano()) - - // setting up nodes - port := rand.Intn(100) + 10000 - - cfg := &config.Config{ - ListenPort: port, - ListenAddr: "0.0.0.0", - Rendezvous: "dione", - PubSub: config.PubSubConfig{ - ProtocolID: "/dione/1.0", - }, - ConsensusMinApprovals: 3, - } - - var nodes []*node.Node - - bNode := newNode(cfg) - t.Logf("Bootstrap ID: %s", bNode.Host.ID()) - cfg.BootstrapNodes = []string{bNode.Host.Addrs()[0].String() + fmt.Sprintf("/p2p/%s", bNode.Host.ID().String())} - nodes = append(nodes, bNode) - - maxNodes := 10 - - for i := 1; i <= maxNodes; i++ { - cfg.ListenPort++ - node := newNode(cfg) - nodes = append(nodes, node) - } - - time.Sleep(5 * time.Second) - -} - -func newNode(cfg *config.Config) *node.Node { - privKey, err := generatePrivateKey() - if err != nil { - logrus.Fatal(err) - } - - node, err := node.NewNode(cfg, privKey, 1*time.Second) - if err != nil { - logrus.Fatal(err) - } - return node -} - -func generatePrivateKey() (crypto.PrivKey, error) { - r := crand.Reader - // Creates a new RSA key pair for this host. - prvKey, _, err := crypto.GenerateKeyPairWithReader(crypto.Ed25519, 2048, r) - if err != nil { - return nil, err - } - return prvKey, nil -} diff --git a/consensus/consensus_validator.go b/consensus/consensus_validator.go new file mode 100644 index 0000000..6ca65cd --- /dev/null +++ b/consensus/consensus_validator.go @@ -0,0 +1,156 @@ +package consensus + +import ( + "github.com/Secured-Finance/dione/cache" + types2 "github.com/Secured-Finance/dione/consensus/types" + "github.com/Secured-Finance/dione/consensus/validation" + "github.com/Secured-Finance/dione/types" + "github.com/ethereum/go-ethereum/common" + "github.com/filecoin-project/go-state-types/crypto" + "github.com/sirupsen/logrus" +) + +type ConsensusValidator struct { + validationFuncMap map[types2.MessageType]func(msg types2.Message) bool + eventCache cache.EventCache + miner *Miner +} + +func NewConsensusValidator(ec cache.EventCache, miner *Miner) *ConsensusValidator { + cv := &ConsensusValidator{ + eventCache: ec, + miner: miner, + } + + cv.validationFuncMap = map[types2.MessageType]func(msg types2.Message) bool{ + types2.MessageTypePrePrepare: func(msg types2.Message) bool { + // TODO here we need to do validation of tx itself + consensusMsg := msg.Payload + + // === verify task signature === + err := VerifyTaskSignature(consensusMsg.Task) + if err != nil { + logrus.Errorf("unable to verify signature: %v", err) + return false + } + ///////////////////////////////// + + // === verify if request exists in event log cache === + requestEvent, err := cv.eventCache.GetOracleRequestEvent("request_" + consensusMsg.Task.RequestID) + if err != nil { + logrus.Errorf("the incoming request task event doesn't exist in the EVC, or is broken: %v", err) + return false + } + if requestEvent.OriginChain != consensusMsg.Task.OriginChain || + requestEvent.RequestType != consensusMsg.Task.RequestType || + requestEvent.RequestParams != consensusMsg.Task.RequestParams { + + logrus.Errorf("the incoming task and cached request event don't match!") + return false + } + ///////////////////////////////// + + // === verify election proof wincount preliminarily === + if consensusMsg.Task.ElectionProof.WinCount < 1 { + logrus.Error("miner isn't a winner!") + return false + } + ///////////////////////////////// + + // === verify miner's eligibility to propose this task === + err = cv.miner.IsMinerEligibleToProposeTask(common.HexToAddress(consensusMsg.Task.MinerEth)) + if err != nil { + logrus.Errorf("miner is not eligible to propose task: %v", err) + return false + } + ///////////////////////////////// + + // === verify election proof vrf === + minerAddressMarshalled, err := consensusMsg.Task.Miner.MarshalBinary() + if err != nil { + logrus.Errorf("failed to marshal miner address: %v", err) + return false + } + electionProofRandomness, err := DrawRandomness( + consensusMsg.Task.BeaconEntries[1].Data, + crypto.DomainSeparationTag_ElectionProofProduction, + consensusMsg.Task.DrandRound, + minerAddressMarshalled, + ) + if err != nil { + logrus.Errorf("failed to draw electionProofRandomness: %v", err) + return false + } + err = VerifyVRF(consensusMsg.Task.Miner, electionProofRandomness, consensusMsg.Task.ElectionProof.VRFProof) + if err != nil { + logrus.Errorf("failed to verify election proof vrf: %v", err) + } + ////////////////////////////////////// + + // === verify ticket vrf === + ticketRandomness, err := DrawRandomness( + consensusMsg.Task.BeaconEntries[1].Data, + crypto.DomainSeparationTag_TicketProduction, + consensusMsg.Task.DrandRound-types.TicketRandomnessLookback, + minerAddressMarshalled, + ) + if err != nil { + logrus.Errorf("failed to draw ticket electionProofRandomness: %v", err) + return false + } + + err = VerifyVRF(consensusMsg.Task.Miner, ticketRandomness, consensusMsg.Task.Ticket.VRFProof) + if err != nil { + logrus.Errorf("failed to verify ticket vrf: %v", err) + } + ////////////////////////////////////// + + // === compute wincount locally and verify values === + mStake, nStake, err := cv.miner.GetStakeInfo(common.HexToAddress(consensusMsg.Task.MinerEth)) + if err != nil { + logrus.Errorf("failed to get miner stake: %v", err) + return false + } + actualWinCount := consensusMsg.Task.ElectionProof.ComputeWinCount(*mStake, *nStake) + if consensusMsg.Task.ElectionProof.WinCount != actualWinCount { + logrus.Errorf("locally computed wincount isn't matching received value!", err) + return false + } + ////////////////////////////////////// + + // === validate payload by specific-chain checks === + if validationFunc := validation.GetValidationMethod(consensusMsg.Task.OriginChain, consensusMsg.Task.RequestType); validationFunc != nil { + err := validationFunc(consensusMsg.Task.Payload) + if err != nil { + logrus.Errorf("payload validation has failed: %v", err) + return false + } + } else { + logrus.Debugf("Origin chain [%v]/request type[%v] doesn't have any payload validation!", consensusMsg.Task.OriginChain, consensusMsg.Task.RequestType) + } + ///////////////////////////////// + + return true + }, + types2.MessageTypePrepare: func(msg types2.Message) bool { + err := VerifyTaskSignature(msg.Payload.Task) + if err != nil { + return false + } + return true + }, + types2.MessageTypeCommit: func(msg types2.Message) bool { + err := VerifyTaskSignature(msg.Payload.Task) + if err != nil { + return false + } + return true + }, + } + + return cv +} + +func (cv *ConsensusValidator) Valid(msg types2.Message) bool { + return cv.validationFuncMap[msg.Type](msg) +} diff --git a/consensus/leader.go b/consensus/leader.go deleted file mode 100644 index 8f6160f..0000000 --- a/consensus/leader.go +++ /dev/null @@ -1,65 +0,0 @@ -package consensus - -import ( - "fmt" - - "github.com/Secured-Finance/dione/sigs" - - "github.com/libp2p/go-libp2p-core/peer" - - "github.com/Secured-Finance/dione/types" - "github.com/filecoin-project/go-state-types/crypto" - "golang.org/x/xerrors" -) - -type SignFunc func(peer.ID, []byte) (*types.Signature, error) - -func ComputeVRF(sign SignFunc, worker peer.ID, sigInput []byte) ([]byte, error) { - sig, err := sign(worker, sigInput) - if err != nil { - return nil, err - } - - if sig.Type != types.SigTypeEd25519 { - return nil, fmt.Errorf("miner worker address was not a Ed25519 key") - } - - return sig.Data, nil -} - -func VerifyVRF(worker peer.ID, vrfBase, vrfproof []byte) error { - err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: vrfproof}, []byte(worker), vrfBase) - if err != nil { - return xerrors.Errorf("vrf was invalid: %w", err) - } - - return nil -} - -func IsRoundWinner(round types.DrandRound, - worker peer.ID, brand types.BeaconEntry, minerStake, networkStake types.BigInt, sign SignFunc) (*types.ElectionProof, error) { - - buf, err := worker.MarshalBinary() - if err != nil { - return nil, xerrors.Errorf("failed to marshal address: %w", err) - } - - electionRand, err := DrawRandomness(brand.Data, crypto.DomainSeparationTag_ElectionProofProduction, round, buf) - if err != nil { - return nil, xerrors.Errorf("failed to draw randomness: %w", err) - } - - vrfout, err := ComputeVRF(sign, worker, electionRand) - if err != nil { - return nil, xerrors.Errorf("failed to compute VRF: %w", err) - } - - ep := &types.ElectionProof{VRFProof: vrfout} - j := ep.ComputeWinCount(minerStake, networkStake) - ep.WinCount = j - if j < 1 { - return nil, nil - } - - return ep, nil -} diff --git a/consensus/msg_log.go b/consensus/msg_log.go new file mode 100644 index 0000000..0bd8011 --- /dev/null +++ b/consensus/msg_log.go @@ -0,0 +1,42 @@ +package consensus + +import ( + types2 "github.com/Secured-Finance/dione/consensus/types" + mapset "github.com/Secured-Finance/golang-set" +) + +type MessageLog struct { + messages mapset.Set + maxLogSize int + validationFuncMap map[types2.MessageType]func(message types2.Message) +} + +func NewMessageLog() *MessageLog { + msgLog := &MessageLog{ + messages: mapset.NewSet(), + maxLogSize: 0, // TODO + } + + return msgLog +} + +func (ml *MessageLog) AddMessage(msg types2.Message) { + ml.messages.Add(msg) +} + +func (ml *MessageLog) Exists(msg types2.Message) bool { + return ml.messages.Contains(msg) +} + +func (ml *MessageLog) GetMessagesByTypeAndConsensusID(typ types2.MessageType, consensusID string) []types2.Message { + var result []types2.Message + + for v := range ml.messages.Iter() { + msg := v.(types2.Message) + if msg.Type == typ && msg.Payload.Task.ConsensusID == consensusID { + result = append(result, msg) + } + } + + return result +} diff --git a/consensus/pre_prepare_pool.go b/consensus/pre_prepare_pool.go deleted file mode 100644 index a9e5a06..0000000 --- a/consensus/pre_prepare_pool.go +++ /dev/null @@ -1,190 +0,0 @@ -package consensus - -import ( - "fmt" - "sync" - - "github.com/Secured-Finance/dione/cache" - - "github.com/Secured-Finance/dione/consensus/validation" - _ "github.com/Secured-Finance/dione/consensus/validation/filecoin" // enable filecoin validation - "github.com/filecoin-project/go-state-types/crypto" - - types2 "github.com/Secured-Finance/dione/consensus/types" - "github.com/Secured-Finance/dione/sigs" - "github.com/Secured-Finance/dione/types" - "github.com/ethereum/go-ethereum/common" - "github.com/mitchellh/hashstructure/v2" - "github.com/sirupsen/logrus" -) - -type PrePreparePool struct { - mut sync.RWMutex - prePrepareMsgs map[string][]*types2.Message - miner *Miner - eventLogCache cache.EventCache -} - -func NewPrePreparePool(miner *Miner, evc cache.EventCache) *PrePreparePool { - return &PrePreparePool{ - prePrepareMsgs: map[string][]*types2.Message{}, - miner: miner, - eventLogCache: evc, - } -} - -func (pp *PrePreparePool) CreatePrePrepare(task *types.DioneTask, requestID string, privateKey []byte) (*types2.Message, error) { - var message types2.Message - message.Type = types2.MessageTypePrePrepare - var consensusMsg types2.ConsensusMessage - consensusMsg.Task.ConsensusID = requestID - consensusMsg.Task.RequestID = requestID - consensusMsg.Task = *task - cHash, err := hashstructure.Hash(task, hashstructure.FormatV2, nil) - if err != nil { - return nil, err - } - signature, err := sigs.Sign(types.SigTypeEd25519, privateKey, []byte(fmt.Sprintf("%v", cHash))) - if err != nil { - return nil, err - } - consensusMsg.Task.Signature = signature.Data - message.Payload = consensusMsg - return &message, nil -} - -func (ppp *PrePreparePool) IsExistingPrePrepare(prepareMsg *types2.Message) bool { - ppp.mut.RLock() - defer ppp.mut.RUnlock() - - consensusMessage := prepareMsg.Payload - var exists bool - for _, v := range ppp.prePrepareMsgs[consensusMessage.Task.ConsensusID] { - if v.From == prepareMsg.From { - exists = true - } - } - return exists -} - -func (ppp *PrePreparePool) IsValidPrePrepare(prePrepare *types2.Message) bool { - // TODO here we need to do validation of tx itself - consensusMsg := prePrepare.Payload - - // === verify task signature === - err := verifyTaskSignature(consensusMsg) - if err != nil { - logrus.Errorf("unable to verify signature: %v", err) - return false - } - ///////////////////////////////// - - // === verify if request exists in event log cache === - requestEvent, err := ppp.eventLogCache.GetOracleRequestEvent("request_" + consensusMsg.Task.RequestID) - if err != nil { - logrus.Errorf("the incoming request task event doesn't exist in the EVC, or is broken: %v", err) - return false - } - if requestEvent.OriginChain != consensusMsg.Task.OriginChain || - requestEvent.RequestType != consensusMsg.Task.RequestType || - requestEvent.RequestParams != consensusMsg.Task.RequestParams { - - logrus.Errorf("the incoming task and cached request event don't match!") - return false - } - ///////////////////////////////// - - // === verify election proof wincount preliminarily === - if consensusMsg.Task.ElectionProof.WinCount < 1 { - logrus.Error("miner isn't a winner!") - return false - } - ///////////////////////////////// - - // === verify miner's eligibility to propose this task === - err = ppp.miner.IsMinerEligibleToProposeTask(common.HexToAddress(consensusMsg.Task.MinerEth)) - if err != nil { - logrus.Errorf("miner is not eligible to propose task: %v", err) - return false - } - ///////////////////////////////// - - // === verify election proof vrf === - minerAddressMarshalled, err := prePrepare.Payload.Task.Miner.MarshalBinary() - if err != nil { - logrus.Errorf("failed to marshal miner address: %v", err) - return false - } - electionProofRandomness, err := DrawRandomness( - consensusMsg.Task.BeaconEntries[1].Data, - crypto.DomainSeparationTag_ElectionProofProduction, - consensusMsg.Task.DrandRound, - minerAddressMarshalled, - ) - if err != nil { - logrus.Errorf("failed to draw electionProofRandomness: %v", err) - return false - } - err = VerifyVRF(consensusMsg.Task.Miner, electionProofRandomness, consensusMsg.Task.ElectionProof.VRFProof) - if err != nil { - logrus.Errorf("failed to verify election proof vrf: %v", err) - } - ////////////////////////////////////// - - // === verify ticket vrf === - ticketRandomness, err := DrawRandomness( - consensusMsg.Task.BeaconEntries[1].Data, - crypto.DomainSeparationTag_TicketProduction, - consensusMsg.Task.DrandRound-types.TicketRandomnessLookback, - minerAddressMarshalled, - ) - if err != nil { - logrus.Errorf("failed to draw ticket electionProofRandomness: %v", err) - return false - } - - err = VerifyVRF(consensusMsg.Task.Miner, ticketRandomness, consensusMsg.Task.Ticket.VRFProof) - if err != nil { - logrus.Errorf("failed to verify ticket vrf: %v", err) - } - ////////////////////////////////////// - - // === compute wincount locally and verify values === - mStake, nStake, err := ppp.miner.GetStakeInfo(common.HexToAddress(consensusMsg.Task.MinerEth)) - if err != nil { - logrus.Errorf("failed to get miner stake: %v", err) - return false - } - actualWinCount := consensusMsg.Task.ElectionProof.ComputeWinCount(*mStake, *nStake) - if consensusMsg.Task.ElectionProof.WinCount != actualWinCount { - logrus.Errorf("locally computed wincount isn't matching received value!", err) - return false - } - ////////////////////////////////////// - - // === validate payload by specific-chain checks === - if validationFunc := validation.GetValidationMethod(consensusMsg.Task.OriginChain, consensusMsg.Task.RequestType); validationFunc != nil { - err := validationFunc(consensusMsg.Task.Payload) - if err != nil { - logrus.Errorf("payload validation has failed: %v", err) - return false - } - } else { - logrus.Debugf("Origin chain [%v]/request type[%v] doesn't have any payload validation!", consensusMsg.Task.OriginChain, consensusMsg.Task.RequestType) - } - ///////////////////////////////// - - return true -} - -func (ppp *PrePreparePool) AddPrePrepare(prePrepare *types2.Message) { - ppp.mut.Lock() - defer ppp.mut.Unlock() - - consensusID := prePrepare.Payload.Task.ConsensusID - if _, ok := ppp.prePrepareMsgs[consensusID]; !ok { - ppp.prePrepareMsgs[consensusID] = []*types2.Message{} - } - - ppp.prePrepareMsgs[consensusID] = append(ppp.prePrepareMsgs[consensusID], prePrepare) -} diff --git a/consensus/prepare_pool.go b/consensus/prepare_pool.go deleted file mode 100644 index 0425ab8..0000000 --- a/consensus/prepare_pool.go +++ /dev/null @@ -1,72 +0,0 @@ -package consensus - -import ( - "sync" - - types2 "github.com/Secured-Finance/dione/consensus/types" -) - -type PreparePool struct { - mut sync.RWMutex - prepareMsgs map[string][]*types2.Message - privateKey []byte -} - -func NewPreparePool() *PreparePool { - return &PreparePool{ - prepareMsgs: map[string][]*types2.Message{}, - } -} - -func (pp *PreparePool) CreatePrepare(prePrepareMsg *types2.Message, privateKey []byte) (*types2.Message, error) { - var message types2.Message - message.Type = types2.MessageTypePrepare - newCMsg := prePrepareMsg.Payload - message.Payload = newCMsg - return &message, nil -} - -func (pp *PreparePool) IsExistingPrepare(prepareMsg *types2.Message) bool { - pp.mut.RLock() - defer pp.mut.RUnlock() - - consensusMessage := prepareMsg.Payload - var exists bool - for _, v := range pp.prepareMsgs[consensusMessage.Task.ConsensusID] { - if v.From == prepareMsg.From { - exists = true - } - } - return exists -} - -func (pp *PreparePool) IsValidPrepare(prepare *types2.Message) bool { - consensusMsg := prepare.Payload - err := verifyTaskSignature(consensusMsg) - if err != nil { - return false - } - return true -} - -func (pp *PreparePool) AddPrepare(prepare *types2.Message) { - pp.mut.Lock() - defer pp.mut.Unlock() - - consensusID := prepare.Payload.Task.ConsensusID - if _, ok := pp.prepareMsgs[consensusID]; !ok { - pp.prepareMsgs[consensusID] = []*types2.Message{} - } - - pp.prepareMsgs[consensusID] = append(pp.prepareMsgs[consensusID], prepare) -} - -func (pp *PreparePool) PreparePoolSize(consensusID string) int { - pp.mut.RLock() - defer pp.mut.RUnlock() - - if v, ok := pp.prepareMsgs[consensusID]; ok { - return len(v) - } - return 0 -} diff --git a/consensus/randomness.go b/consensus/randomness.go deleted file mode 100644 index 3353b15..0000000 --- a/consensus/randomness.go +++ /dev/null @@ -1,31 +0,0 @@ -package consensus - -import ( - "encoding/binary" - - "github.com/Secured-Finance/dione/types" - "github.com/filecoin-project/go-state-types/crypto" - "github.com/minio/blake2b-simd" - "golang.org/x/xerrors" -) - -func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round types.DrandRound, entropy []byte) ([]byte, error) { - h := blake2b.New256() - if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil { - return nil, xerrors.Errorf("deriving randomness: %w", err) - } - VRFDigest := blake2b.Sum256(rbase) - _, err := h.Write(VRFDigest[:]) - if err != nil { - return nil, xerrors.Errorf("hashing VRFDigest: %w", err) - } - if err := binary.Write(h, binary.BigEndian, round); err != nil { - return nil, xerrors.Errorf("deriving randomness: %w", err) - } - _, err = h.Write(entropy) - if err != nil { - return nil, xerrors.Errorf("hashing entropy: %w", err) - } - - return h.Sum(nil), nil -} diff --git a/consensus/utils.go b/consensus/utils.go index 9e2a22e..d1813a0 100644 --- a/consensus/utils.go +++ b/consensus/utils.go @@ -1,22 +1,104 @@ package consensus import ( + "encoding/binary" "fmt" - "github.com/Secured-Finance/dione/consensus/types" - "github.com/Secured-Finance/dione/sigs" - types2 "github.com/Secured-Finance/dione/types" + types2 "github.com/Secured-Finance/dione/consensus/types" + "github.com/mitchellh/hashstructure/v2" + + "github.com/Secured-Finance/dione/sigs" + "github.com/minio/blake2b-simd" + + "github.com/libp2p/go-libp2p-core/peer" + + "github.com/Secured-Finance/dione/types" + "github.com/filecoin-project/go-state-types/crypto" + "golang.org/x/xerrors" ) -func verifyTaskSignature(msg types.ConsensusMessage) error { - cHash, err := hashstructure.Hash(msg.Task, hashstructure.FormatV2, nil) +type SignFunc func(peer.ID, []byte) (*types.Signature, error) + +func ComputeVRF(sign SignFunc, worker peer.ID, sigInput []byte) ([]byte, error) { + sig, err := sign(worker, sigInput) + if err != nil { + return nil, err + } + + if sig.Type != types.SigTypeEd25519 { + return nil, fmt.Errorf("miner worker address was not a Ed25519 key") + } + + return sig.Data, nil +} + +func VerifyVRF(worker peer.ID, vrfBase, vrfproof []byte) error { + err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: vrfproof}, []byte(worker), vrfBase) + if err != nil { + return xerrors.Errorf("vrf was invalid: %w", err) + } + + return nil +} + +func IsRoundWinner(round types.DrandRound, + worker peer.ID, brand types.BeaconEntry, minerStake, networkStake types.BigInt, sign SignFunc) (*types.ElectionProof, error) { + + buf, err := worker.MarshalBinary() + if err != nil { + return nil, xerrors.Errorf("failed to marshal address: %w", err) + } + + electionRand, err := DrawRandomness(brand.Data, crypto.DomainSeparationTag_ElectionProofProduction, round, buf) + if err != nil { + return nil, xerrors.Errorf("failed to draw randomness: %w", err) + } + + vrfout, err := ComputeVRF(sign, worker, electionRand) + if err != nil { + return nil, xerrors.Errorf("failed to compute VRF: %w", err) + } + + ep := &types.ElectionProof{VRFProof: vrfout} + j := ep.ComputeWinCount(minerStake, networkStake) + ep.WinCount = j + if j < 1 { + return nil, nil + } + + return ep, nil +} + +func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round types.DrandRound, entropy []byte) ([]byte, error) { + h := blake2b.New256() + if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil { + return nil, xerrors.Errorf("deriving randomness: %v", err) + } + VRFDigest := blake2b.Sum256(rbase) + _, err := h.Write(VRFDigest[:]) + if err != nil { + return nil, xerrors.Errorf("hashing VRFDigest: %w", err) + } + if err := binary.Write(h, binary.BigEndian, round); err != nil { + return nil, xerrors.Errorf("deriving randomness: %v", err) + } + _, err = h.Write(entropy) + if err != nil { + return nil, xerrors.Errorf("hashing entropy: %v", err) + } + + return h.Sum(nil), nil +} + +func VerifyTaskSignature(task types.DioneTask) error { + cHash, err := hashstructure.Hash(task, hashstructure.FormatV2, nil) if err != nil { return err } err = sigs.Verify( - &types2.Signature{Type: types2.SigTypeEd25519, Data: msg.Task.Signature}, - []byte(msg.Task.Miner), + &types.Signature{Type: types.SigTypeEd25519, Data: task.Signature}, + []byte(task.Miner), []byte(fmt.Sprintf("%v", cHash)), ) if err != nil { @@ -24,3 +106,28 @@ func verifyTaskSignature(msg types.ConsensusMessage) error { } return nil } + +func NewMessage(msg *types2.Message, typ types2.MessageType) (types2.Message, error) { + var newMsg types2.Message + newMsg.Type = typ + newCMsg := msg.Payload + newMsg.Payload = newCMsg + return newMsg, nil +} + +func CreatePrePrepareWithTaskSignature(task *types.DioneTask, privateKey []byte) (*types2.Message, error) { + var message types2.Message + message.Type = types2.MessageTypePrePrepare + + cHash, err := hashstructure.Hash(task, hashstructure.FormatV2, nil) + if err != nil { + return nil, err + } + signature, err := sigs.Sign(types.SigTypeEd25519, privateKey, []byte(fmt.Sprintf("%v", cHash))) + if err != nil { + return nil, err + } + task.Signature = signature.Data + message.Payload = types2.ConsensusMessage{Task: *task} + return &message, nil +} diff --git a/consensus/validation/payload_validation_manager.go b/consensus/validation/payload_validator.go similarity index 100% rename from consensus/validation/payload_validation_manager.go rename to consensus/validation/payload_validator.go diff --git a/drand/drand.go b/drand/drand.go index f940e65..529f158 100644 --- a/drand/drand.go +++ b/drand/drand.go @@ -26,7 +26,9 @@ import ( types "github.com/Secured-Finance/dione/types" ) -var log = logging.Logger("drand") +var log = logrus.WithFields(logrus.Fields{ + "subsystem": "drand", +}) // DrandResponse structure representing response from drand network type DrandResponse struct { @@ -61,7 +63,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub) (*DrandBeacon } dlogger := dlog.NewKitLoggerFrom(kzap.NewZapSugarLogger( - log.SugaredLogger.Desugar(), zapcore.InfoLevel)) + logging.Logger("drand").SugaredLogger.Desugar(), zapcore.InfoLevel)) var clients []client.Client for _, url := range cfg.Servers { @@ -82,7 +84,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub) (*DrandBeacon if ps != nil { opts = append(opts, libp2pClient.WithPubsub(ps)) } else { - logrus.Info("Initiated drand with PubSub") + log.Info("Initiated drand with PubSub") } drandClient, err := client.Wrap(clients, opts...) @@ -117,7 +119,7 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Be go func() { start := lib.Clock.Now() - logrus.Info("start fetching randomness", "round", round) + log.Infof("start fetching randomness: round %v", round) resp, err := db.DrandClient.Get(ctx, round) var br beacon.BeaconResult @@ -127,7 +129,7 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Be br.Entry.Round = resp.Round() br.Entry.Data = resp.Signature() } - logrus.Info("done fetching randomness", "round", round, "took", lib.Clock.Since(start)) + log.Infof("done fetching randomness: round %v, took %v", round, lib.Clock.Since(start)) out <- br close(out) }() @@ -172,7 +174,7 @@ func (db *DrandBeacon) VerifyEntry(curr, prev types.BeaconEntry) error { func (db *DrandBeacon) LatestBeaconRound() uint64 { latestDround, err := db.DrandClient.Get(context.TODO(), 0) if err != nil { - logrus.Errorf("failed to get latest drand round: %w", err) + log.Errorf("failed to get latest drand round: %w", err) } return latestDround.Round() } diff --git a/eth-contracts/common/deployment.ts b/eth-contracts/common/deployment.ts index 3da8d23..19c0ede 100644 --- a/eth-contracts/common/deployment.ts +++ b/eth-contracts/common/deployment.ts @@ -121,6 +121,6 @@ class LogWrapper { } public log(message?: any, ...optionalParams: any[]): void { - if(this.enabled) console.log(message, optionalParams); + if(this.enabled) console.log(message, ...optionalParams); } } \ No newline at end of file diff --git a/eth-contracts/package.json b/eth-contracts/package.json index 46b7999..312ea78 100644 --- a/eth-contracts/package.json +++ b/eth-contracts/package.json @@ -7,7 +7,7 @@ "test": "TS_NODE_FILES=true npx hardhat test", "test:reportGas": "REPORT_GAS=1 TS_NODE_FILES=true npx hardhat test", "coverage": "TS_NODE_FILES=true npx hardhat coverage", - "deployLocal": "TS_NODE_FILES=true npx hardhat --network geth run scripts/deploy.ts" + "deploy:local": "TS_NODE_FILES=true npx hardhat --network geth run scripts/deploy.ts" }, "author": "", "license": "ISC", diff --git a/go.mod b/go.mod index 9149dbb..a809fa9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,8 @@ module github.com/Secured-Finance/dione go 1.14 require ( - github.com/Secured-Finance/go-libp2p-pex v1.0.1 + github.com/Secured-Finance/go-libp2p-pex v1.1.0 + github.com/Secured-Finance/golang-set v1.8.0 github.com/VictoriaMetrics/fastcache v1.5.7 github.com/aristanetworks/goarista v0.0.0-20210308203447-b196d8410f1d // indirect github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect @@ -24,15 +25,16 @@ require ( github.com/go-ozzo/ozzo-validation v3.6.0+incompatible github.com/go-redis/redis/v8 v8.7.0 github.com/gobwas/ws v1.0.4 // indirect + github.com/gogo/protobuf v1.3.2 // indirect github.com/google/uuid v1.1.5 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/huin/goupnp v1.0.1-0.20200620063722-49508fba0031 // indirect github.com/ipfs/go-log v1.0.4 github.com/jmoiron/sqlx v1.2.0 github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect + github.com/klauspost/cpuid/v2 v2.0.6 // indirect github.com/libp2p/go-libp2p v0.12.0 github.com/libp2p/go-libp2p-core v0.7.0 - github.com/libp2p/go-libp2p-crypto v0.1.0 github.com/libp2p/go-libp2p-pubsub v0.4.2-0.20210212194758-6c1addf493eb github.com/mattn/go-sqlite3 v1.11.0 github.com/miguelmota/go-ethereum-hdwallet v0.0.0-20210314074952-8dd49aa599b9 @@ -40,12 +42,13 @@ require ( github.com/mitchellh/hashstructure/v2 v2.0.1 github.com/mitchellh/mapstructure v1.3.3 // indirect github.com/multiformats/go-multiaddr v0.3.1 + github.com/multiformats/go-multihash v0.0.15 // indirect github.com/olekukonko/tablewriter v0.0.4 // indirect github.com/raulk/clock v1.1.0 github.com/rjeczalik/notify v0.9.2 // indirect github.com/rs/cors v1.7.0 // indirect github.com/shengdoushi/base58 v1.0.0 - github.com/sirupsen/logrus v1.7.0 + github.com/sirupsen/logrus v1.8.1 github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.7.1 github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 // indirect @@ -55,9 +58,10 @@ require ( github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2 github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 go.uber.org/zap v1.16.0 - golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 + golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect - golang.org/x/sys v0.0.0-20210313202042-bd2e13477e9c // indirect + golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect + golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 honnef.co/go/tools v0.0.1-2020.1.3 // indirect nhooyr.io/websocket v1.8.6 // indirect diff --git a/go.sum b/go.sum index ab2e90c..5bf985f 100644 --- a/go.sum +++ b/go.sum @@ -56,8 +56,10 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/Secured-Finance/go-libp2p-pex v1.0.1 h1:JpQ+TP37QaAtTG2g57WmmkXZ+62IYC+aTMcDvwG3Vlc= -github.com/Secured-Finance/go-libp2p-pex v1.0.1/go.mod h1:Q4llSmPACDBpWvqHT/nU95t8BbR96aE4dZb7eO3xqqE= +github.com/Secured-Finance/go-libp2p-pex v1.1.0 h1:u+VQmzKmECZJTCkmUwQw0NGU1xHQIZjY7gYElLOxl0o= +github.com/Secured-Finance/go-libp2p-pex v1.1.0/go.mod h1:pMq1xsaluhIIdY8dALk/U7NH5N+naUCo/1jRgh8YNsI= +github.com/Secured-Finance/golang-set v1.8.0 h1:2z3Aymw/LtvPsfRIJbX2p6xiSIQFxByzmGd2xYU0H9E= +github.com/Secured-Finance/golang-set v1.8.0/go.mod h1:NLdE4DjG2Aw84FTUFyspBP33PcmrRMxfNrrd+Eo9vJI= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs= github.com/Shopify/sarama v1.28.0/go.mod h1:j/2xTrU39dlzBmsxF1eQ2/DdWrxyBCl6pzz7a81o/ZY= @@ -446,8 +448,9 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/status v1.0.3/go.mod h1:SavQ51ycCLnc7dGyJxp8YAmudx8xqiVrRf+6IXRsugc= github.com/gogo/status v1.1.0 h1:+eIkrewn5q6b30y+g/BJINVVdi2xH7je5MPJ3ZPK3JA= github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM= @@ -872,6 +875,7 @@ github.com/kilic/bls12-381 v0.0.0-20200820230200-6b2c19996391 h1:51kHw7l/dUDdOdW github.com/kilic/bls12-381 v0.0.0-20200820230200-6b2c19996391/go.mod h1:XXfR6YFCRSrkEXbNlIyDsgXVNJWVUV30m/ebkVy9n6s= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= @@ -880,9 +884,12 @@ github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.9 h1:5OCMOdde1TCT2sookEuVeEZzA8bmRSFV3AwPDZAG8AA= github.com/klauspost/compress v1.11.9/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid/v2 v2.0.2/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.6 h1:dQ5ueTiftKxp0gyjKSx5+8BtPWkyQbd95m8Gys/RarI= +github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/reedsolomon v1.9.2/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= github.com/klauspost/reedsolomon v1.9.11/go.mod h1:nLvuzNvy1ZDNQW30IuMc2ZWCbiqrJgdLoUS2X8HAUVg= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -1005,6 +1012,8 @@ github.com/libp2p/go-libp2p-core v0.6.0/go.mod h1:txwbVEhHEXikXn9gfC7/UDDw7rkxuX github.com/libp2p/go-libp2p-core v0.6.1/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-core v0.7.0 h1:4a0TMjrWNTZlNvcqxZmrMRDi/NQWrhwO2pkTuLSQ/IQ= github.com/libp2p/go-libp2p-core v0.7.0/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= +github.com/libp2p/go-libp2p-core v0.8.5 h1:aEgbIcPGsKy6zYcC+5AJivYFedhYa4sW7mIpWpUaLKw= +github.com/libp2p/go-libp2p-core v0.8.5/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE= github.com/libp2p/go-libp2p-crypto v0.0.2/go.mod h1:eETI5OUfBnvARGOHrJz2eWNyTUxEGZnBxMcbUjfIj4I= github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ= @@ -1282,8 +1291,9 @@ github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+ github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= -github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= +github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -1353,8 +1363,9 @@ github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa github.com/multiformats/go-multihash v0.0.9/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= -github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I= github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= +github.com/multiformats/go-multihash v0.0.15 h1:hWOPdrNqDjwHDx82vsYGSDZNyktOJJ2dzZJzFkOV1jM= +github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg= github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/multiformats/go-multistream v0.0.4/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= @@ -1583,8 +1594,9 @@ github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745/go.mod h1:G81a github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= @@ -1758,6 +1770,7 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: github.com/xtaci/kcp-go v5.4.5+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= @@ -1862,8 +1875,9 @@ golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201112155050-0c6587e931a9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1939,6 +1953,7 @@ golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= @@ -1953,8 +1968,9 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -2055,8 +2071,10 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210313202042-bd2e13477e9c h1:coiPEfMv+ThsjULRDygLrJVlNE1gDdL2g65s0LhV2os= -golang.org/x/sys v0.0.0-20210313202042-bd2e13477e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 h1:dXfMednGJh/SUUFjTLsWJz3P+TQt9qnR11GgeI3vWKs= +golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -2065,8 +2083,9 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -2114,9 +2133,11 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200827010519-17fd2f27a9e3/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/node/node.go b/node/node.go index 002af70..f429497 100644 --- a/node/node.go +++ b/node/node.go @@ -235,13 +235,13 @@ func (n *Node) subscribeOnEthContractsAsync(ctx context.Context) { task, err := n.Miner.MineTask(context.TODO(), event) if err != nil { - logrus.Fatal("Failed to mine task, exiting... ", err) + logrus.Errorf("Failed to mine task: %v", err) } if task == nil { continue } logrus.Infof("Proposed new Dione task with ID: %s", event.ReqID.String()) - err = n.ConsensusManager.Propose(*task, event) + err = n.ConsensusManager.Propose(*task) if err != nil { logrus.Errorf("Failed to propose task: %w", err) }