Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e473f629bd | ||
|
|
46bb25402f | ||
|
|
052a791875 | ||
|
|
b8f2de2def | ||
|
|
96a5e579cf | ||
|
|
5f4efedbdd | ||
|
|
9d49c6861f | ||
|
|
3b56288a5e | ||
|
|
f257f4febb | ||
|
|
df867f3349 | ||
|
|
5270c20263 | ||
|
|
7762cd0a68 | ||
|
|
e91cc9cd08 | ||
|
|
741825a04e | ||
|
|
49b27da426 | ||
|
|
bf4bbd15e5 | ||
|
|
baa69c3c81 | ||
|
|
ac644605f2 | ||
|
|
94da339622 |
@@ -101,6 +101,7 @@ type FullNode interface {
|
||||
WalletSetDefault(context.Context, address.Address) error
|
||||
WalletExport(context.Context, address.Address) (*types.KeyInfo, error)
|
||||
WalletImport(context.Context, *types.KeyInfo) (address.Address, error)
|
||||
WalletDelete(context.Context, address.Address) error
|
||||
|
||||
// Other
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ type FullNodeStruct struct {
|
||||
WalletSetDefault func(context.Context, address.Address) error `perm:"admin"`
|
||||
WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"`
|
||||
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
||||
WalletDelete func(context.Context, address.Address) error `perm:"write"`
|
||||
|
||||
ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"`
|
||||
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
||||
@@ -438,6 +439,10 @@ func (c *FullNodeStruct) WalletImport(ctx context.Context, ki *types.KeyInfo) (a
|
||||
return c.Internal.WalletImport(ctx, ki)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) WalletDelete(ctx context.Context, addr address.Address) error {
|
||||
return c.Internal.WalletDelete(ctx, addr)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
||||
return c.Internal.MpoolGetNonce(ctx, addr)
|
||||
}
|
||||
|
||||
@@ -34,3 +34,12 @@ func BuiltinBootstrap() ([]peer.AddrInfo, error) {
|
||||
})
|
||||
return out, err
|
||||
}
|
||||
|
||||
func DrandBootstrap() ([]peer.AddrInfo, error) {
|
||||
addrs := []string{
|
||||
"/dnsaddr/pl-eu.testnet.drand.sh/",
|
||||
"/dnsaddr/pl-us.testnet.drand.sh/",
|
||||
"/dnsaddr/pl-sin.testnet.drand.sh/",
|
||||
}
|
||||
return addrutil.ParseAddresses(context.TODO(), addrs)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWALjK9ai1gzssE4H9kwmS7CVqkENedeJJzmgVS9YMtLii
|
||||
/ip4/34.217.110.132/tcp/1347/p2p/12D3KooWALjK9ai1gzssE4H9kwmS7CVqkENedeJJzmgVS9YMtLii
|
||||
/dns4/peer0.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWSJYjQMi2MGaeyRAWvDnEAAC7GdFSRXk5Lns6G1ajSMA7
|
||||
/ip4/54.187.182.170/tcp/1347/p2p/12D3KooWSJYjQMi2MGaeyRAWvDnEAAC7GdFSRXk5Lns6G1ajSMA7
|
||||
/dns4/peer1.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWPdeoNGcaGTxWdENfzEYJ9WqGVkJAxi2aHpX4TjkbeGkj
|
||||
/ip4/52.24.84.39/tcp/1347/p2p/12D3KooWPdeoNGcaGTxWdENfzEYJ9WqGVkJAxi2aHpX4TjkbeGkj
|
||||
/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWLVgeFhXA7ztuSS1uvk4NVzZwRZLxg8PBy1mJuHfc8J6E
|
||||
/ip4/34.217.110.132/tcp/1347/p2p/12D3KooWLVgeFhXA7ztuSS1uvk4NVzZwRZLxg8PBy1mJuHfc8J6E
|
||||
/dns4/peer0.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWBkXWpT1hLHXz7VzR8ZHCJ42P6c9Nb9532ATSguBpLTKJ
|
||||
/ip4/54.187.182.170/tcp/1347/p2p/12D3KooWBkXWpT1hLHXz7VzR8ZHCJ42P6c9Nb9532ATSguBpLTKJ
|
||||
/dns4/peer1.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWJk5hQHNdCsidtX4jhKQMBXKJdo2kjhrNHUZBPmCZKwKt
|
||||
/ip4/52.24.84.39/tcp/1347/p2p/12D3KooWJk5hQHNdCsidtX4jhKQMBXKJdo2kjhrNHUZBPmCZKwKt
|
||||
|
||||
Binary file not shown.
+12
-8
@@ -91,15 +91,16 @@ func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if parent.Height() > rheight {
|
||||
return nil, xerrors.Errorf("cache is inconsistent")
|
||||
}
|
||||
|
||||
rheight -= ci.skipLength
|
||||
|
||||
skipTarget, err := ci.walkBack(parent, rheight)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var skipTarget *types.TipSet
|
||||
if parent.Height() < rheight {
|
||||
skipTarget = parent
|
||||
} else {
|
||||
skipTarget, err = ci.walkBack(parent, rheight)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("fillCache walkback: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
lbe := &lbEntry{
|
||||
@@ -113,8 +114,9 @@ func (ci *ChainIndex) fillCache(tsk types.TipSetKey) (*lbEntry, error) {
|
||||
return lbe, nil
|
||||
}
|
||||
|
||||
// floors to nearest skipLength multiple
|
||||
func (ci *ChainIndex) roundHeight(h abi.ChainEpoch) abi.ChainEpoch {
|
||||
return abi.ChainEpoch(h/ci.skipLength) * ci.skipLength
|
||||
return (h/ci.skipLength) * ci.skipLength
|
||||
}
|
||||
|
||||
func (ci *ChainIndex) roundDown(ts *types.TipSet) (*types.TipSet, error) {
|
||||
@@ -146,6 +148,8 @@ func (ci *ChainIndex) walkBack(from *types.TipSet, to abi.ChainEpoch) (*types.Ti
|
||||
}
|
||||
|
||||
if to > pts.Height() {
|
||||
// in case pts is lower than the epoch we're looking for (null blocks)
|
||||
// return a tipset above that height
|
||||
return ts, nil
|
||||
}
|
||||
if to == pts.Height() {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package store_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/gen"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types/mock"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
datastore "github.com/ipfs/go-datastore"
|
||||
syncds "github.com/ipfs/go-datastore/sync"
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIndexSeeks(t *testing.T) {
|
||||
cg, err := gen.NewGenerator()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gencar, err := cg.GenesisCar()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gen := cg.Genesis()
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
nbs := blockstore.NewBlockstore(syncds.MutexWrap(datastore.NewMapDatastore()))
|
||||
cs := store.NewChainStore(nbs, syncds.MutexWrap(datastore.NewMapDatastore()), nil)
|
||||
|
||||
_, err = cs.Import(bytes.NewReader(gencar))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cur := mock.TipSet(gen)
|
||||
if err := cs.PutTipSet(ctx, mock.TipSet(gen)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cs.SetGenesis(gen)
|
||||
|
||||
// Put 113 blocks from genesis
|
||||
for i := 0; i < 113; i++ {
|
||||
nextts := mock.TipSet(mock.MkBlock(cur, 1, 1))
|
||||
|
||||
if err := cs.PutTipSet(ctx, nextts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cur = nextts
|
||||
}
|
||||
|
||||
// Put 50 null epochs + 1 block
|
||||
skip := mock.MkBlock(cur, 1, 1)
|
||||
skip.Height += 50
|
||||
|
||||
skipts := mock.TipSet(skip)
|
||||
|
||||
if err := cs.PutTipSet(ctx, skipts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ts, err := cs.GetTipsetByHeight(ctx, skip.Height-10, skipts, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, abi.ChainEpoch(164), ts.Height())
|
||||
|
||||
for i := 0; i <= 113; i++ {
|
||||
ts3, err := cs.GetTipsetByHeight(ctx, abi.ChainEpoch(i), skipts, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, abi.ChainEpoch(i), ts3.Height())
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,11 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pstateRoot := c
|
||||
if parents != nil {
|
||||
pstateRoot = parents.Blocks()[0].ParentStateRoot
|
||||
}
|
||||
|
||||
var pcids []cid.Cid
|
||||
var height abi.ChainEpoch
|
||||
weight := types.NewInt(weightInc)
|
||||
@@ -72,7 +77,7 @@ func MkBlock(parents *types.TipSet, weightInc uint64, ticketNonce uint64) *types
|
||||
ParentWeight: weight,
|
||||
Messages: c,
|
||||
Height: height,
|
||||
ParentStateRoot: c,
|
||||
ParentStateRoot: pstateRoot,
|
||||
BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS, Data: []byte("boo! im a signature")},
|
||||
}
|
||||
}
|
||||
|
||||
+22
-4
@@ -22,10 +22,11 @@ import (
|
||||
var log = logging.Logger("wallet")
|
||||
|
||||
const (
|
||||
KNamePrefix = "wallet-"
|
||||
KDefault = "default"
|
||||
KTBLS = "bls"
|
||||
KTSecp256k1 = "secp256k1"
|
||||
KNamePrefix = "wallet-"
|
||||
KTrashPrefix = "trash-"
|
||||
KDefault = "default"
|
||||
KTBLS = "bls"
|
||||
KTSecp256k1 = "secp256k1"
|
||||
)
|
||||
|
||||
type Wallet struct {
|
||||
@@ -230,6 +231,23 @@ func (w *Wallet) HasKey(addr address.Address) (bool, error) {
|
||||
return k != nil, nil
|
||||
}
|
||||
|
||||
func (w *Wallet) DeleteKey(addr address.Address) error {
|
||||
k, err := w.findKey(addr)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to delete key %s : %w", addr, err)
|
||||
}
|
||||
|
||||
if err := w.keystore.Put(KTrashPrefix+k.Address.String(), k.KeyInfo); err != nil {
|
||||
return xerrors.Errorf("failed to mark key %s as trashed: %w", addr, err)
|
||||
}
|
||||
|
||||
if err := w.keystore.Delete(KNamePrefix + k.Address.String()); err != nil {
|
||||
return xerrors.Errorf("failed to delete key %s: %w", addr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
types.KeyInfo
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ var walletCmd = &cli.Command{
|
||||
walletSetDefault,
|
||||
walletSign,
|
||||
walletVerify,
|
||||
walletDelete,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -375,3 +376,28 @@ var walletVerify = &cli.Command{
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var walletDelete = &cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "Delete an account from the wallet",
|
||||
ArgsUsage: "<address> ",
|
||||
Action: func(cctx *cli.Context) error {
|
||||
api, closer, err := GetFullNodeAPI(cctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
if !cctx.Args().Present() || cctx.NArg() != 1 {
|
||||
return fmt.Errorf("must specify address to delete")
|
||||
}
|
||||
|
||||
addr, err := address.NewFromString(cctx.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.WalletDelete(ctx, addr)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -30,12 +30,13 @@ require (
|
||||
github.com/filecoin-project/go-statestore v0.1.0
|
||||
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b
|
||||
github.com/filecoin-project/sector-storage v0.0.0-20200605192746-4b9317d1f08f
|
||||
github.com/filecoin-project/specs-actors v0.5.5
|
||||
github.com/filecoin-project/specs-actors v0.5.6
|
||||
github.com/filecoin-project/specs-storage v0.0.0-20200417134612-61b2d91a6102
|
||||
github.com/filecoin-project/storage-fsm v0.0.0-20200605082304-aa405b2176aa
|
||||
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
|
||||
github.com/go-kit/kit v0.10.0
|
||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/gorilla/mux v1.7.4
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
|
||||
@@ -227,6 +227,8 @@ github.com/filecoin-project/specs-actors v0.3.0/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVl
|
||||
github.com/filecoin-project/specs-actors v0.5.4-0.20200521014528-0df536f7e461/go.mod h1:r5btrNzZD0oBkEz1pohv80gSCXQnqGrD0kYwOTiExyE=
|
||||
github.com/filecoin-project/specs-actors v0.5.5 h1:bDsowem6dLRc9B7g3sgFYvHgfWTH4D9q5ehWLGLdKCw=
|
||||
github.com/filecoin-project/specs-actors v0.5.5/go.mod h1:dRdy3cURykh2R8O/DKqy8olScl70rmIS7GrB4hB1IDY=
|
||||
github.com/filecoin-project/specs-actors v0.5.6 h1:WlhtoXwFoKlP1b06NI4NJaxC4m9EXNV+qFVl43/xRN8=
|
||||
github.com/filecoin-project/specs-actors v0.5.6/go.mod h1:dRdy3cURykh2R8O/DKqy8olScl70rmIS7GrB4hB1IDY=
|
||||
github.com/filecoin-project/specs-storage v0.0.0-20200417134612-61b2d91a6102 h1:T3f/zkuvgtgqcXrb0NO3BicuveGOxxUAMPa/Yif2kuE=
|
||||
github.com/filecoin-project/specs-storage v0.0.0-20200417134612-61b2d91a6102/go.mod h1:xJ1/xl9+8zZeSSSFmDC3Wr6uusCTxyYPI0VeNVSFmPE=
|
||||
github.com/filecoin-project/storage-fsm v0.0.0-20200605082304-aa405b2176aa h1:kTCIBKMhhhVcjCh1ws72vpdDr4cdZjCyIUDFijuWuvA=
|
||||
@@ -292,6 +294,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
|
||||
+2
-1
@@ -153,13 +153,14 @@ func (m *Miner) mine(ctx context.Context) {
|
||||
m.niceSleep(build.BlockDelay * time.Second)
|
||||
continue
|
||||
}
|
||||
lastBase = *base
|
||||
|
||||
b, err := m.mineOne(ctx, base)
|
||||
if err != nil {
|
||||
log.Errorf("mining block failed: %+v", err)
|
||||
m.niceSleep(time.Second)
|
||||
continue
|
||||
}
|
||||
lastBase = *base
|
||||
|
||||
onDone(b != nil)
|
||||
|
||||
|
||||
@@ -218,6 +218,7 @@ func Online() Option {
|
||||
// TODO: Fix offline mode
|
||||
|
||||
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
|
||||
Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap),
|
||||
|
||||
Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
|
||||
|
||||
|
||||
@@ -800,9 +800,7 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
|
||||
return types.EmptyInt, err
|
||||
}
|
||||
|
||||
// TODO: !!!! Use method that doesnt trigger additional state mutations, this is going to cause lots of objects to be created and written to disk
|
||||
log.Warnf("calling inefficient unlock vested funds method, fixme")
|
||||
vested, err := st.UnlockVestedFunds(as, ts.Height())
|
||||
vested, err := st.CheckVestedFunds(as, ts.Height())
|
||||
if err != nil {
|
||||
return types.EmptyInt, err
|
||||
}
|
||||
|
||||
@@ -76,3 +76,7 @@ func (a *WalletAPI) WalletExport(ctx context.Context, addr address.Address) (*ty
|
||||
func (a *WalletAPI) WalletImport(ctx context.Context, ki *types.KeyInfo) (address.Address, error) {
|
||||
return a.Wallet.Import(ki)
|
||||
}
|
||||
|
||||
func (a *WalletAPI) WalletDelete(ctx context.Context, addr address.Address) error {
|
||||
return a.Wallet.DeleteKey(addr)
|
||||
}
|
||||
|
||||
@@ -89,3 +89,7 @@ func ConfigBootstrap(peers []string) func() (dtypes.BootstrapPeers, error) {
|
||||
func BuiltinBootstrap() (dtypes.BootstrapPeers, error) {
|
||||
return build.BuiltinBootstrap()
|
||||
}
|
||||
|
||||
func DrandBootstrap() (dtypes.DrandBootstrap, error) {
|
||||
return build.DrandBootstrap()
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ package dtypes
|
||||
import "github.com/libp2p/go-libp2p-core/peer"
|
||||
|
||||
type BootstrapPeers []peer.AddrInfo
|
||||
type DrandBootstrap []peer.AddrInfo
|
||||
|
||||
type Bootstrapper bool
|
||||
|
||||
+92
-13
@@ -2,6 +2,7 @@ package lp2p
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
host "github.com/libp2p/go-libp2p-core/host"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
blake2b "github.com/minio/blake2b-simd"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/node/config"
|
||||
@@ -28,17 +30,48 @@ func init() {
|
||||
pubsub.GossipSubDlazy = 12
|
||||
pubsub.GossipSubDirectConnectInitialDelay = 30 * time.Second
|
||||
}
|
||||
|
||||
func ScoreKeeper() *dtypes.ScoreKeeper {
|
||||
return new(dtypes.ScoreKeeper)
|
||||
}
|
||||
|
||||
func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtypes.NetworkName, bp dtypes.BootstrapPeers, cfg *config.Pubsub, sk *dtypes.ScoreKeeper) (service *pubsub.PubSub, err error) {
|
||||
type GossipIn struct {
|
||||
fx.In
|
||||
Mctx helpers.MetricsCtx
|
||||
Lc fx.Lifecycle
|
||||
Host host.Host
|
||||
Nn dtypes.NetworkName
|
||||
Bp dtypes.BootstrapPeers
|
||||
Db dtypes.DrandBootstrap
|
||||
Cfg *config.Pubsub
|
||||
Sk *dtypes.ScoreKeeper
|
||||
}
|
||||
|
||||
func getDrandTopic() (string, error) {
|
||||
var drandInfo = struct {
|
||||
Hash string `json:"hash"`
|
||||
}{}
|
||||
err := json.Unmarshal([]byte(build.DrandChain), &drandInfo)
|
||||
if err != nil {
|
||||
return "", xerrors.Errorf("could not unmarshal drand chain info: %w", err)
|
||||
}
|
||||
return "/drand/pubsub/v0.0.0/" + drandInfo.Hash, nil
|
||||
}
|
||||
|
||||
func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
|
||||
bootstrappers := make(map[peer.ID]struct{})
|
||||
for _, pi := range bp {
|
||||
for _, pi := range in.Bp {
|
||||
bootstrappers[pi.ID] = struct{}{}
|
||||
}
|
||||
isBootstrapNode := cfg.Bootstrapper
|
||||
drandBootstrappers := make(map[peer.ID]struct{})
|
||||
for _, pi := range in.Db {
|
||||
drandBootstrappers[pi.ID] = struct{}{}
|
||||
}
|
||||
|
||||
isBootstrapNode := in.Cfg.Bootstrapper
|
||||
drandTopic, err := getDrandTopic()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options := []pubsub.Option{
|
||||
// Gossipsubv1.1 configuration
|
||||
@@ -56,6 +89,11 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
return 2500
|
||||
}
|
||||
|
||||
_, ok = drandBootstrappers[p]
|
||||
if ok && !isBootstrapNode {
|
||||
return 1500
|
||||
}
|
||||
|
||||
// TODO: we want to plug the application specific score to the node itself in order
|
||||
// to provide feedback to the pubsub system based on observed behaviour
|
||||
return 0
|
||||
@@ -80,7 +118,48 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
|
||||
// topic parameters
|
||||
Topics: map[string]*pubsub.TopicScoreParams{
|
||||
build.BlocksTopic(nn): {
|
||||
drandTopic: {
|
||||
// expected 2 beaconsn/min
|
||||
TopicWeight: 0.5, // 5x block topic
|
||||
|
||||
// 1 tick per second, maxes at 1 after 1 hour
|
||||
TimeInMeshWeight: 0.00027, // ~1/3600
|
||||
TimeInMeshQuantum: time.Second,
|
||||
TimeInMeshCap: 1,
|
||||
|
||||
// deliveries decay after 1 hour, cap at 100 blocks
|
||||
FirstMessageDeliveriesWeight: 5, // max value is 500
|
||||
FirstMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour),
|
||||
FirstMessageDeliveriesCap: 100, // 100 blocks in an hour
|
||||
|
||||
// Mesh Delivery Failure is currently turned off for blocks
|
||||
// This is on purpose as
|
||||
// - the traffic is very low for meaningful distribution of incoming edges.
|
||||
// - the reaction time needs to be very slow -- in the order of 10 min at least
|
||||
// so we might as well let opportunistic grafting repair the mesh on its own
|
||||
// pace.
|
||||
// - the network is too small, so large asymmetries can be expected between mesh
|
||||
// edges.
|
||||
// We should revisit this once the network grows.
|
||||
//
|
||||
// // tracks deliveries in the last minute
|
||||
// // penalty activates at 1 minute and expects ~0.4 blocks
|
||||
// MeshMessageDeliveriesWeight: -576, // max penalty is -100
|
||||
// MeshMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Minute),
|
||||
// MeshMessageDeliveriesCap: 10, // 10 blocks in a minute
|
||||
// MeshMessageDeliveriesThreshold: 0.41666, // 10/12/2 blocks/min
|
||||
// MeshMessageDeliveriesWindow: 10 * time.Millisecond,
|
||||
// MeshMessageDeliveriesActivation: time.Minute,
|
||||
//
|
||||
// // decays after 15 min
|
||||
// MeshFailurePenaltyWeight: -576,
|
||||
// MeshFailurePenaltyDecay: pubsub.ScoreParameterDecay(15 * time.Minute),
|
||||
|
||||
// invalid messages decay after 1 hour
|
||||
InvalidMessageDeliveriesWeight: -1000,
|
||||
InvalidMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour),
|
||||
},
|
||||
build.BlocksTopic(in.Nn): {
|
||||
// expected 10 blocks/min
|
||||
TopicWeight: 0.1, // max is 50, max mesh penalty is -10, single invalid message is -100
|
||||
|
||||
@@ -121,7 +200,7 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
InvalidMessageDeliveriesWeight: -1000,
|
||||
InvalidMessageDeliveriesDecay: pubsub.ScoreParameterDecay(time.Hour),
|
||||
},
|
||||
build.MessagesTopic(nn): {
|
||||
build.MessagesTopic(in.Nn): {
|
||||
// expected > 1 tx/second
|
||||
TopicWeight: 0.05, // max is 25, max mesh penalty is -5, single invalid message is -100
|
||||
|
||||
@@ -166,7 +245,7 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
OpportunisticGraftThreshold: 5,
|
||||
},
|
||||
),
|
||||
pubsub.WithPeerScoreInspect(sk.Update, 10*time.Second),
|
||||
pubsub.WithPeerScoreInspect(in.Sk.Update, 10*time.Second),
|
||||
}
|
||||
|
||||
// enable Peer eXchange on bootstrappers
|
||||
@@ -184,10 +263,10 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
}
|
||||
|
||||
// direct peers
|
||||
if cfg.DirectPeers != nil {
|
||||
if in.Cfg.DirectPeers != nil {
|
||||
var directPeerInfo []peer.AddrInfo
|
||||
|
||||
for _, addr := range cfg.DirectPeers {
|
||||
for _, addr := range in.Cfg.DirectPeers {
|
||||
a, err := ma.NewMultiaddr(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -205,8 +284,8 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
}
|
||||
|
||||
// tracer
|
||||
if cfg.RemoteTracer != "" {
|
||||
a, err := ma.NewMultiaddr(cfg.RemoteTracer)
|
||||
if in.Cfg.RemoteTracer != "" {
|
||||
a, err := ma.NewMultiaddr(in.Cfg.RemoteTracer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -216,7 +295,7 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tr, err := pubsub.NewRemoteTracer(context.TODO(), host, *pi)
|
||||
tr, err := pubsub.NewRemoteTracer(context.TODO(), in.Host, *pi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,7 +308,7 @@ func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtyp
|
||||
// in peer scores for debugging purposes -- this might be trigged by metrics collection
|
||||
// options = append(options, pubsub.WithPeerScoreInspect(XXX, time.Second))
|
||||
|
||||
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, options...)
|
||||
return pubsub.NewGossipSub(helpers.LifecycleCtx(in.Mctx, in.Lc), in.Host, options...)
|
||||
}
|
||||
|
||||
func HashMsgId(m *pubsub_pb.Message) string {
|
||||
|
||||
Reference in New Issue
Block a user