Implement vdf execution and timing

pull/471/head
Rongjian Lan 6 years ago
parent d71ee04eae
commit 0bd637639c
  1. 3
      consensus/consensus_leader.go
  2. 4
      crypto/vdf/vdf.go
  3. 15
      drand/drand_leader.go
  4. 5
      node/node.go

@ -36,9 +36,6 @@ func (consensus *Consensus) WaitForNewBlock(blockChannel chan *types.Block, stop
for {
select {
default:
// got the signal to start consensus
_ = <-startChannel
utils.GetLogInstance().Debug("Waiting for block", "consensus", consensus)
// keep waiting for new blocks
newBlock := <-blockChannel

@ -37,7 +37,9 @@ func (vdf *VDF) Execute() {
tempResult = sha3.Sum256(tempResult[:])
}
vdf.output = tempResult
vdf.outputChan <- vdf.output
go func() {
vdf.outputChan <- vdf.output
}()
vdf.finished = true
}

@ -3,7 +3,7 @@ package drand
import (
"bytes"
"encoding/binary"
"fmt"
"time"
"github.com/harmony-one/harmony/crypto/vdf"
@ -17,7 +17,7 @@ import (
)
const (
vdfDifficulty = 10000000
vdfDifficulty = 1000000
)
// WaitForEpochBlock waits for the first epoch block to run DRG on
@ -40,15 +40,18 @@ func (dRand *DRand) WaitForEpochBlock(blockChannel chan *types.Block, stopChan c
vdf := vdf.New(vdfDifficulty, input)
outputChannel := vdf.GetOutputChannel()
start := time.Now()
vdf.Execute()
duration := time.Now().Sub(start)
utils.GetLogInstance().Info("VDF computation finished", "time spent", duration.String())
output := <-outputChannel
rndBytes := [64]byte{}
rndBytes := [64]byte{} // The first 32 bytes are the randomness and the last 32 bytes are the hash of the block where the corresponding pRnd was generated
copy(rndBytes[:32], output[:])
fmt.Println("TESTTEST")
fmt.Println(rndBytes)
blockHash := newBlock.Hash()
copy(rndBytes[32:], blockHash[:])
fmt.Println(rndBytes)
dRand.RndChannel <- rndBytes
}()
}

@ -4,7 +4,6 @@ import (
"bytes"
"crypto/ecdsa"
"encoding/binary"
"encoding/hex"
"fmt"
"math/big"
"os"
@ -27,7 +26,7 @@ import (
proto_node "github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/api/service"
service_manager "github.com/harmony-one/harmony/api/service"
blockproposal "github.com/harmony-one/harmony/api/service/blockproposal"
"github.com/harmony-one/harmony/api/service/blockproposal"
"github.com/harmony-one/harmony/api/service/clientsupport"
consensus_service "github.com/harmony-one/harmony/api/service/consensus"
"github.com/harmony-one/harmony/api/service/discovery"
@ -304,8 +303,6 @@ func New(host p2p.Host, consensus *bft.Consensus, db ethdb.Database) *Node {
if node.Role == BeaconLeader || node.Role == BeaconValidator {
node.CurrentStakes = make(map[common.Address]int64)
}
bytes, _ := rlp.EncodeToBytes(chain.GetBlockByNumber(0))
utils.GetLogInstance().Debug("TESTTEST", "block", hex.EncodeToString(bytes))
utils.GetLogInstance().Debug("Received", "blockHash", chain.GetBlockByNumber(0).Hash().Hex())
node.Consensus.ConsensusBlock = make(chan *bft.BFTBlockInfo)
node.Consensus.VerifiedNewBlock = make(chan *types.Block)

Loading…
Cancel
Save