Compiling with the new weight func
This commit is contained in:
parent
7d471a6ce3
commit
29f26cb8d1
@ -61,6 +61,7 @@ type FullNode interface {
|
|||||||
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
||||||
ChainSetHead(context.Context, *types.TipSet) error
|
ChainSetHead(context.Context, *types.TipSet) error
|
||||||
ChainGetGenesis(context.Context) (*types.TipSet, error)
|
ChainGetGenesis(context.Context) (*types.TipSet, error)
|
||||||
|
ChainTipSetWeight(context.Context, *types.TipSet) (types.BigInt, error)
|
||||||
|
|
||||||
// syncer
|
// syncer
|
||||||
SyncState(context.Context) (*SyncState, error)
|
SyncState(context.Context) (*SyncState, error)
|
||||||
@ -130,7 +131,6 @@ type FullNode interface {
|
|||||||
StateWaitMsg(context.Context, cid.Cid) (*MsgWait, error)
|
StateWaitMsg(context.Context, cid.Cid) (*MsgWait, error)
|
||||||
StateListMiners(context.Context, *types.TipSet) ([]address.Address, error)
|
StateListMiners(context.Context, *types.TipSet) ([]address.Address, error)
|
||||||
StateListActors(context.Context, *types.TipSet) ([]address.Address, error)
|
StateListActors(context.Context, *types.TipSet) ([]address.Address, error)
|
||||||
StateTipSetWeight(context.Context, *types.TipSet) (types.BigInt, error)
|
|
||||||
|
|
||||||
PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error)
|
PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error)
|
||||||
PaychList(context.Context) ([]address.Address, error)
|
PaychList(context.Context) ([]address.Address, error)
|
||||||
|
@ -49,6 +49,7 @@ type FullNodeStruct struct {
|
|||||||
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
|
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
|
||||||
ChainSetHead func(context.Context, *types.TipSet) error `perm:"admin"`
|
ChainSetHead func(context.Context, *types.TipSet) error `perm:"admin"`
|
||||||
ChainGetGenesis func(context.Context) (*types.TipSet, error) `perm:"read"`
|
ChainGetGenesis func(context.Context) (*types.TipSet, error) `perm:"read"`
|
||||||
|
ChainTipSetWeight func(context.Context, *types.TipSet) (types.BigInt, error) `perm:"read"`
|
||||||
|
|
||||||
SyncState func(context.Context) (*SyncState, error) `perm:"read"`
|
SyncState func(context.Context) (*SyncState, error) `perm:"read"`
|
||||||
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
|
SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"`
|
||||||
@ -97,7 +98,6 @@ type FullNodeStruct struct {
|
|||||||
StateWaitMsg func(context.Context, cid.Cid) (*MsgWait, error) `perm:"read"`
|
StateWaitMsg func(context.Context, cid.Cid) (*MsgWait, error) `perm:"read"`
|
||||||
StateListMiners func(context.Context, *types.TipSet) ([]address.Address, error) `perm:"read"`
|
StateListMiners func(context.Context, *types.TipSet) ([]address.Address, error) `perm:"read"`
|
||||||
StateListActors func(context.Context, *types.TipSet) ([]address.Address, error) `perm:"read"`
|
StateListActors func(context.Context, *types.TipSet) ([]address.Address, error) `perm:"read"`
|
||||||
StateTipSetWeight func(context.Context, *types.TipSet) (types.BigInt, error) `perm:"read"`
|
|
||||||
|
|
||||||
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) `perm:"sign"`
|
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) `perm:"sign"`
|
||||||
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
|
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
|
||||||
@ -317,6 +317,10 @@ func (c *FullNodeStruct) ChainGetGenesis(ctx context.Context) (*types.TipSet, er
|
|||||||
return c.Internal.ChainGetGenesis(ctx)
|
return c.Internal.ChainGetGenesis(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) ChainTipSetWeight(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
||||||
|
return c.Internal.ChainTipSetWeight(ctx, ts)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) SyncState(ctx context.Context) (*SyncState, error) {
|
func (c *FullNodeStruct) SyncState(ctx context.Context) (*SyncState, error) {
|
||||||
return c.Internal.SyncState(ctx)
|
return c.Internal.SyncState(ctx)
|
||||||
}
|
}
|
||||||
@ -379,10 +383,6 @@ func (c *FullNodeStruct) StateListActors(ctx context.Context, ts *types.TipSet)
|
|||||||
return c.Internal.StateListActors(ctx, ts)
|
return c.Internal.StateListActors(ctx, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) StateTipSetWeight(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
|
||||||
return c.Internal.StateTipSetWeight(ctx, ts)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) {
|
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) {
|
||||||
return c.Internal.PaychGet(ctx, from, to, ensureFunds)
|
return c.Internal.PaychGet(ctx, from, to, ensureFunds)
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,11 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
|
|||||||
}
|
}
|
||||||
|
|
||||||
next.BLSAggregate = aggSig
|
next.BLSAggregate = aggSig
|
||||||
pweight := sm.ChainStore().Weight(parents)
|
pweight, err := sm.ChainStore().Weight(ctx, parents)
|
||||||
next.ParentWeight = types.NewInt(pweight)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
next.ParentWeight = pweight
|
||||||
|
|
||||||
cst := hamt.CSTFromBstore(sm.ChainStore().Blockstore())
|
cst := hamt.CSTFromBstore(sm.ChainStore().Blockstore())
|
||||||
tree, err := state.LoadStateTree(cst, st)
|
tree, err := state.LoadStateTree(cst, st)
|
||||||
|
@ -89,11 +89,16 @@ func sendHeadNotifs(ctx context.Context, ps *pubsub.PubSub, topic string, chain
|
|||||||
case notif := <-notifs:
|
case notif := <-notifs:
|
||||||
n := notif[len(notif)-1]
|
n := notif[len(notif)-1]
|
||||||
|
|
||||||
|
w, err := chain.ChainTipSetWeight(ctx, n.Val)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
m := message{
|
m := message{
|
||||||
Cids: n.Val.Cids(),
|
Cids: n.Val.Cids(),
|
||||||
Blocks: n.Val.Blocks(),
|
Blocks: n.Val.Blocks(),
|
||||||
Height: n.Val.Height(),
|
Height: n.Val.Height(),
|
||||||
Weight: n.Val.Weight(),
|
Weight: w,
|
||||||
NodeName: nickname,
|
NodeName: nickname,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ func computeMsgMeta(bs amt.Blocks, bmsgCids, smsgCids []cbg.CBORMarshaler) (cid.
|
|||||||
return mrcid, nil
|
return mrcid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (syncer *Syncer) selectHead(heads map[peer.ID]*types.TipSet) (*types.TipSet, error) {
|
func (syncer *Syncer) selectHead(ctx context.Context, heads map[peer.ID]*types.TipSet) (*types.TipSet, error) {
|
||||||
var headsArr []*types.TipSet
|
var headsArr []*types.TipSet
|
||||||
for _, ts := range heads {
|
for _, ts := range heads {
|
||||||
headsArr = append(headsArr, ts)
|
headsArr = append(headsArr, ts)
|
||||||
@ -298,7 +298,16 @@ func (syncer *Syncer) selectHead(heads map[peer.ID]*types.TipSet) (*types.TipSet
|
|||||||
return nil, fmt.Errorf("Conflict exists in heads set")
|
return nil, fmt.Errorf("Conflict exists in heads set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if syncer.store.Weight(cur) > syncer.store.Weight(sel) {
|
curw, err := syncer.store.Weight(ctx, cur)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selw, err := syncer.store.Weight(ctx, sel)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if curw.GreaterThan(selw) {
|
||||||
sel = cur
|
sel = cur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,7 +361,7 @@ func (syncer *Syncer) Sync(ctx context.Context, maybeHead *types.TipSet) error {
|
|||||||
return xerrors.Errorf("collectChain failed: %w", err)
|
return xerrors.Errorf("collectChain failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syncer.store.PutTipSet(maybeHead); err != nil {
|
if err := syncer.store.PutTipSet(ctx, maybeHead); err != nil {
|
||||||
return xerrors.Errorf("failed to put synced tipset to chainstore: %w", err)
|
return xerrors.Errorf("failed to put synced tipset to chainstore: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func (m *Miner) mine(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
base, err := m.GetBestMiningCandidate()
|
base, err := m.GetBestMiningCandidate(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to get best mining candidate: %s", err)
|
log.Errorf("failed to get best mining candidate: %s", err)
|
||||||
continue
|
continue
|
||||||
@ -199,8 +199,8 @@ type MiningBase struct {
|
|||||||
tickets []*types.Ticket
|
tickets []*types.Ticket
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Miner) GetBestMiningCandidate() (*MiningBase, error) {
|
func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error) {
|
||||||
bts, err := m.api.ChainHead(context.TODO())
|
bts, err := m.api.ChainHead(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -210,7 +210,16 @@ func (m *Miner) GetBestMiningCandidate() (*MiningBase, error) {
|
|||||||
return m.lastWork, nil
|
return m.lastWork, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if types.BigCmp(bts.Weight(), m.lastWork.ts.Weight()) <= 0 {
|
btsw, err := m.api.ChainTipSetWeight(ctx, bts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ltsw, err := m.api.ChainTipSetWeight(ctx, m.lastWork.ts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if types.BigCmp(btsw, ltsw) <= 0 {
|
||||||
return m.lastWork, nil
|
return m.lastWork, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package hello
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -26,7 +27,7 @@ func init() {
|
|||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
HeaviestTipSet []cid.Cid
|
HeaviestTipSet []cid.Cid
|
||||||
HeaviestTipSetWeight uint64
|
HeaviestTipSetWeight types.BigInt
|
||||||
GenesisHash cid.Cid
|
GenesisHash cid.Cid
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +84,10 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
|
|||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
hts := hs.cs.GetHeaviestTipSet()
|
hts := hs.cs.GetHeaviestTipSet()
|
||||||
weight := hs.cs.Weight(hts)
|
weight, err := hs.cs.Weight(ctx, hts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
gen, err := hs.cs.GetGenesis()
|
gen, err := hs.cs.GetGenesis()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -160,3 +160,7 @@ func (a *ChainAPI) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {
|
|||||||
|
|
||||||
return types.NewTipSet([]*types.BlockHeader{genb})
|
return types.NewTipSet([]*types.BlockHeader{genb})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ChainAPI) ChainTipSetWeight(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
||||||
|
return a.Chain.Weight(ctx, ts)
|
||||||
|
}
|
||||||
|
@ -226,7 +226,3 @@ func (a *StateAPI) StateListMiners(ctx context.Context, ts *types.TipSet) ([]add
|
|||||||
func (a *StateAPI) StateListActors(ctx context.Context, ts *types.TipSet) ([]address.Address, error) {
|
func (a *StateAPI) StateListActors(ctx context.Context, ts *types.TipSet) ([]address.Address, error) {
|
||||||
return a.StateManager.ListAllActors(ctx, ts)
|
return a.StateManager.ListAllActors(ctx, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *StateAPI) StateTipSetWeight(ctx context.Context, ts *types.TipSet) (types.BigInt, error) {
|
|
||||||
return a.Chain.Weight(ctx, ts)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user