some small cleanup
This commit is contained in:
parent
0feab0aad4
commit
4e6839b5ef
@ -2,7 +2,6 @@ package drand
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -118,7 +117,6 @@ func (db *DrandBeacon) handleStreamingUpdates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e := range ch {
|
for e := range ch {
|
||||||
fmt.Println("Entry: ", e.Round, e.Signature)
|
|
||||||
db.cacheValue(types.BeaconEntry{
|
db.cacheValue(types.BeaconEntry{
|
||||||
Round: e.Round,
|
Round: e.Round,
|
||||||
Data: e.Signature,
|
Data: e.Signature,
|
||||||
@ -130,7 +128,7 @@ func (db *DrandBeacon) handleStreamingUpdates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response {
|
func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response {
|
||||||
fmt.Println("requesting drand entry: ", round)
|
// check cache, it it if there, otherwise query the endpoint
|
||||||
cres := db.getCachedValue(round)
|
cres := db.getCachedValue(round)
|
||||||
if cres != nil {
|
if cres != nil {
|
||||||
out := make(chan beacon.Response, 1)
|
out := make(chan beacon.Response, 1)
|
||||||
@ -142,7 +140,6 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Re
|
|||||||
out := make(chan beacon.Response, 1)
|
out := make(chan beacon.Response, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// check cache, it it if there, otherwise query the endpoint
|
|
||||||
resp, err := db.client.PublicRand(ctx, db.peers[0], &dproto.PublicRandRequest{Round: round})
|
resp, err := db.client.PublicRand(ctx, db.peers[0], &dproto.PublicRandRequest{Round: round})
|
||||||
|
|
||||||
var br beacon.Response
|
var br beacon.Response
|
||||||
@ -196,13 +193,9 @@ func (db *DrandBeacon) VerifyEntry(curr types.BeaconEntry, prev types.BeaconEntr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) uint64 {
|
func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) uint64 {
|
||||||
fmt.Println("MAX BEACON ROUND FOR EPOCH: ", filEpoch)
|
|
||||||
fmt.Println("filecoin genesis time: ", db.filGenTime)
|
|
||||||
fmt.Println("drand genesis time: ", db.drandGenTime)
|
|
||||||
// TODO: sometimes the genesis time for filecoin is zero and this goes negative
|
// TODO: sometimes the genesis time for filecoin is zero and this goes negative
|
||||||
latestTs := ((uint64(filEpoch) * db.filRoundTime) + db.filGenTime) - db.filRoundTime
|
latestTs := ((uint64(filEpoch) * db.filRoundTime) + db.filGenTime) - db.filRoundTime
|
||||||
dround := (latestTs - db.drandGenTime) / uint64(db.interval.Seconds())
|
dround := (latestTs - db.drandGenTime) / uint64(db.interval.Seconds())
|
||||||
fmt.Println("max beacon round will be: ", dround)
|
|
||||||
return dround
|
return dround
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +215,6 @@ func NewGenerator() (*ChainGen, error) {
|
|||||||
miners := []address.Address{maddr1, maddr2}
|
miners := []address.Address{maddr1, maddr2}
|
||||||
|
|
||||||
beac := beacon.NewMockBeacon(time.Second)
|
beac := beacon.NewMockBeacon(time.Second)
|
||||||
//beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay)
|
|
||||||
//if err != nil {
|
|
||||||
//return nil, xerrors.Errorf("could not create beacon: %w", err)
|
|
||||||
//}
|
|
||||||
|
|
||||||
gen := &ChainGen{
|
gen := &ChainGen{
|
||||||
bs: bs,
|
bs: bs,
|
||||||
|
@ -893,7 +893,6 @@ func (cs *ChainStore) TryFillTipSet(ts *types.TipSet) (*FullTipSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) {
|
||||||
//log.Desugar().WithOptions(zap.AddCallerSkip(2)).Sugar().Warnw("DrawRandomness", "base", rbase, "dsep", pers, "round", round, "entropy", entropy)
|
|
||||||
h := blake2b.New256()
|
h := blake2b.New256()
|
||||||
if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil {
|
if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil {
|
||||||
return nil, xerrors.Errorf("deriving randomness: %w", err)
|
return nil, xerrors.Errorf("deriving randomness: %w", err)
|
||||||
|
@ -2,7 +2,6 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
@ -384,8 +383,5 @@ func MinerRandomBeacon(api lapi.FullNode) (beacon.RandomBeacon, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Making miner random beacon: ", gents.Blocks()[0].Timestamp)
|
|
||||||
|
|
||||||
//return beacon.NewMockBeacon(build.BlockDelay * time.Second)
|
|
||||||
return drand.NewDrandBeacon(gents.Blocks()[0].Timestamp, build.BlockDelay)
|
return drand.NewDrandBeacon(gents.Blocks()[0].Timestamp, build.BlockDelay)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user