Skip to content

Commit

Permalink
feat: extract msig transaction hamt
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Nov 13, 2020
1 parent 4db18f7 commit b9d469c
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 19 deletions.
32 changes: 25 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,62 @@ go 1.14
require (
contrib.go.opencensus.io/exporter/prometheus v0.1.0
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/filecoin-project/go-address v0.0.4
github.com/filecoin-project/go-bitfield v0.2.1
github.com/filecoin-project/go-fil-markets v1.0.0
github.com/fatih/color v1.10.0 // indirect
github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200910194244-f640612a1a1f // indirect
github.com/filecoin-project/go-address v0.0.5-0.20201103152444-f2023ef3f5bb
github.com/filecoin-project/go-bitfield v0.2.3-0.20201110211213-fe2c1862e816
github.com/filecoin-project/go-data-transfer v1.1.0 // indirect
github.com/filecoin-project/go-fil-markets v1.0.4
github.com/filecoin-project/go-multistore v0.0.3
github.com/filecoin-project/go-state-types v0.0.0-20201013222834-41ea465f274f
github.com/filecoin-project/lotus v1.1.3-0.20201031000550-a5c05f87f15f
github.com/filecoin-project/lotus v1.1.3-rc1
github.com/filecoin-project/specs-actors v0.9.12
github.com/filecoin-project/specs-actors/v2 v2.2.0
github.com/filecoin-project/statediff v0.0.8-0.20201027195725-7eaa5391a639
github.com/git-chglog/git-chglog v0.0.0-20200414013904-db796966b373 // indirect
github.com/go-pg/migrations/v8 v8.0.1
github.com/go-pg/pg/v10 v10.3.1
github.com/go-pg/pgext v0.1.4
github.com/hashicorp/golang-lru v0.5.4
github.com/imdario/mergo v0.3.11 // indirect
github.com/ipfs/go-bitswap v0.3.1 // indirect
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-blockservice v0.1.4 // indirect
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-ipfs-blockstore v1.0.1
github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf
github.com/ipfs/go-ipfs-blockstore v1.0.2
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4
github.com/ipld/go-ipld-prime v0.5.1-0.20200910124733-350032422383
github.com/ipld/go-ipld-prime v0.5.1-0.20201021195245-109253e8a018
github.com/jackc/pgx/v4 v4.9.0
github.com/lib/pq v1.8.0
github.com/libp2p/go-libp2p-kad-dht v0.11.0 // indirect
github.com/libp2p/go-libp2p-peer v0.2.0
github.com/libp2p/go-libp2p-pubsub v0.4.0 // indirect
github.com/libp2p/go-libp2p-quic-transport v0.9.0 // indirect
github.com/libp2p/go-libp2p-yamux v0.4.1 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multihash v0.0.14
github.com/prometheus/client_golang v1.6.0
github.com/raulk/clock v1.1.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/testify v1.6.1
github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect
github.com/urfave/cli v1.22.5 // indirect
github.com/urfave/cli/v2 v2.2.0
github.com/whyrusleeping/cbor-gen v0.0.0-20200826160007-0b9f6c5fb163
github.com/willscott/carbs v0.0.3
go.opencensus.io v0.22.4
go.opentelemetry.io/otel v0.12.0
go.opentelemetry.io/otel/exporters/trace/jaeger v0.12.0
go.opentelemetry.io/otel/sdk v0.12.0
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
gopkg.in/AlecAivazis/survey.v1 v1.8.8 // indirect
gopkg.in/kyokomi/emoji.v1 v1.5.1 // indirect
)

replace github.com/filecoin-project/filecoin-ffi => github.com/filecoin-project/statediff/extern/filecoin-ffi v0.0.0-20201028183730-8e6631500d49
Expand Down
107 changes: 106 additions & 1 deletion go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lens/carrepo/carrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/lib/cachebs"
"github.com/filecoin-project/lotus/lib/bufbstore"
"github.com/filecoin-project/lotus/lib/ulimit"
marketevents "github.com/filecoin-project/lotus/markets/loggers"
"github.com/filecoin-project/lotus/node/impl"
Expand Down Expand Up @@ -63,7 +63,7 @@ func NewAPIOpener(c *cli.Context) (*APIOpener, lens.APICloser, error) {
return nil, nil, err
}

cs := store.NewChainStore(cacheDB, mds, vm.Syscalls(&fakeVerifier{}), journal.NilJournal())
cs := store.NewChainStore(cacheDB, cacheDB, mds, vm.Syscalls(&fakeVerifier{}), journal.NilJournal())

headKey, err := db.Roots()
if err != nil {
Expand Down Expand Up @@ -111,8 +111,8 @@ func (ra *CarAPI) ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, ga

func (ra *CarAPI) Store() adt.Store {
bs := ra.FullNodeAPI.ChainAPI.Chain.Blockstore()
cachedStore := cachebs.NewBufferedBstore(bs, ra.cacheSize)
cs := cbor.NewCborStore(cachedStore)
bufferedStore := bufbstore.NewBufferedBstore(bs)
cs := cbor.NewCborStore(bufferedStore)
adtStore := adt.WrapStore(ra.Context, cs)
return adtStore
}
Expand Down
7 changes: 4 additions & 3 deletions lens/lotusrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/lib/cachebs"
"github.com/filecoin-project/lotus/lib/bufbstore"
"github.com/filecoin-project/lotus/lib/ulimit"
marketevents "github.com/filecoin-project/lotus/markets/loggers"
"github.com/filecoin-project/lotus/node/impl"
Expand Down Expand Up @@ -72,7 +72,8 @@ func NewAPIOpener(c *cli.Context) (*APIOpener, lens.APICloser, error) {
return nil, nil, err
}

cs := store.NewChainStore(blockstore.NewBlockstore(ds), mds, vm.Syscalls(&fakeVerifier{}), journal.NilJournal())
bs := blockstore.NewBlockstore(ds)
cs := store.NewChainStore(bs, bs, mds, vm.Syscalls(&fakeVerifier{}), journal.NilJournal())
if err := cs.Load(); err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -110,7 +111,7 @@ func (ra *RepoAPI) ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, g

func (ra *RepoAPI) Store() adt.Store {
bs := ra.FullNodeAPI.ChainAPI.Chain.Blockstore()
cachedStore := cachebs.NewBufferedBstore(bs, ra.cacheSize)
cachedStore := bufbstore.NewBufferedBstore(bs)
cs := cbor.NewCborStore(cachedStore)
adtStore := adt.WrapStore(ra.Context, cs)
return adtStore
Expand Down
6 changes: 3 additions & 3 deletions lens/sqlrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/lib/cachebs"
"github.com/filecoin-project/lotus/lib/bufbstore"
"github.com/filecoin-project/lotus/lib/ulimit"
marketevents "github.com/filecoin-project/lotus/markets/loggers"
"github.com/filecoin-project/lotus/node/impl"
Expand Down Expand Up @@ -59,7 +59,7 @@ func NewAPIOpener(c *cli.Context) (*APIOpener, lens.APICloser, error) {
return nil, nil, err
}

cs := store.NewChainStore(bs, mds, vm.Syscalls(&fakeVerifier{}), journal.NilJournal())
cs := store.NewChainStore(bs, bs, mds, vm.Syscalls(&fakeVerifier{}), journal.NilJournal())

headKey, err := bs.(*SqlBlockstore).getMasterTsKey(c.Context, safetyLookBack)
if err != nil {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (ra *SQLAPI) ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, ga

func (ra *SQLAPI) Store() adt.Store {
bs := ra.FullNodeAPI.ChainAPI.Chain.Blockstore()
cachedStore := cachebs.NewBufferedBstore(bs, ra.cacheSize)
cachedStore := bufbstore.NewBufferedBstore(bs)
cs := cbor.NewCborStore(cachedStore)
adtStore := adt.WrapStore(ra.Context, cs)
return adtStore
Expand Down
20 changes: 20 additions & 0 deletions model/actors/multisig/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package multisig

import (
"context"

"github.com/go-pg/pg/v10"
)

type MultisigTaskResult struct {
TransactionModel MultisigTransactionList
}

func (m *MultisigTaskResult) Persist(ctx context.Context, db *pg.DB) error {
return db.RunInTransaction(ctx, func(tx *pg.Tx) error {
if len(m.TransactionModel) > 0 {
return m.TransactionModel.PersistWithTx(ctx, tx)
}
return nil
})
}
54 changes: 54 additions & 0 deletions model/actors/multisig/transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package multisig

import (
"context"

"github.com/go-pg/pg/v10"
"golang.org/x/xerrors"
)

type MultisigTransaction struct {
MultisigID string `pg:",pk,notnull"`
StateRoot string `pg:",pk,notnull"`
Height int64 `pg:",pk,notnull,use_zero"`
TransactionID int64 `pg:",pk,notnull,use_zero"`

// Transaction State
To string `pg:",notnull"`
Value string `pg:",notnull"`
Method uint64 `pg:",notnull,use_zero"`
Params []byte
Approved []string `pg:",notnull"`
}

func (m *MultisigTransaction) PersistWithTx(ctx context.Context, tx *pg.Tx) error {
if _, err := tx.ModelContext(ctx, m).
OnConflict("do nothing").
Insert(); err != nil {
return xerrors.Errorf("persisting multisig transaction: %w", err)
}
return nil
}

func (m *MultisigTransaction) Persist(ctx context.Context, db *pg.DB) error {
return db.RunInTransaction(ctx, func(tx *pg.Tx) error {
return m.PersistWithTx(ctx, tx)
})
}

type MultisigTransactionList []*MultisigTransaction

func (ml MultisigTransactionList) PersistWithTx(ctx context.Context, tx *pg.Tx) error {
if _, err := tx.ModelContext(ctx, ml).
OnConflict("do nothing").
Insert(); err != nil {
return xerrors.Errorf("persisting multisig transaction list: %w", err)
}
return nil
}

func (ml MultisigTransactionList) Persist(ctx context.Context, db *pg.DB) error {
return db.RunInTransaction(ctx, func(tx *pg.Tx) error {
return ml.PersistWithTx(ctx, tx)
})
}
12 changes: 12 additions & 0 deletions model/genesis/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
init_ "github.com/filecoin-project/sentinel-visor/model/actors/init"
"github.com/filecoin-project/sentinel-visor/model/actors/market"
"github.com/filecoin-project/sentinel-visor/model/actors/miner"
"github.com/filecoin-project/sentinel-visor/model/actors/multisig"
"github.com/filecoin-project/sentinel-visor/model/actors/power"
)

type ProcessGenesisSingletonResult struct {
minerResults miner.MinerTaskResultList
msigResults multisig.MultisigTransactionList
marketResult *GenesisMarketTaskResult
initActorResult *GenesisInitActorTaskResult
powerResult *power.PowerTaskResult
Expand Down Expand Up @@ -54,10 +56,20 @@ func (r *ProcessGenesisSingletonResult) Persist(ctx context.Context, db *pg.DB)
return err
}
}
// persist multisig actor
if r.msigResults != nil {
if err := r.msigResults.PersistWithTx(ctx, tx); err != nil {
return err
}
}
return nil
})
}

func (r *ProcessGenesisSingletonResult) AddMsig(m multisig.MultisigTransactionList) {
r.msigResults = append(r.msigResults, m...)
}

func (r *ProcessGenesisSingletonResult) AddMiner(m *miner.MinerTaskResult) {
r.minerResults = append(r.minerResults, m)
}
Expand Down
31 changes: 31 additions & 0 deletions storage/migrations/17_msig_transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package migrations

import (
"github.com/go-pg/migrations/v8"
)

// Schema version 17 adds multisig transactions

func init() {
up := batch(`
CREATE TABLE IF NOT EXISTS "multisig_transactions" (
"height" bigint not null,
"multisig_id" text not null,
"state_root" text not null,
"transaction_id" text not null,
"to" text not null,
"value" text not null,
"method" bigint not null,
"params" bytea not null,
"approved" json not null,
PRIMARY KEY ("height", "state_root", "multisig_id", "transaction_id")
);
`)

down := batch(`
DROP TABLE IF EXISTS public.multisig_transactions;
`)

migrations.MustRegisterTx(up, down)
}
15 changes: 14 additions & 1 deletion tasks/actorstate/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
initmodel "github.com/filecoin-project/sentinel-visor/model/actors/init"
marketmodel "github.com/filecoin-project/sentinel-visor/model/actors/market"
minermodel "github.com/filecoin-project/sentinel-visor/model/actors/miner"
multisigmodel "github.com/filecoin-project/sentinel-visor/model/actors/multisig"
powermodel "github.com/filecoin-project/sentinel-visor/model/actors/power"
genesismodel "github.com/filecoin-project/sentinel-visor/model/genesis"
"github.com/filecoin-project/sentinel-visor/storage"
Expand Down Expand Up @@ -43,6 +44,7 @@ func (p *GenesisProcessor) ProcessGenesis(ctx context.Context, gen *types.TipSet
return xerrors.Errorf("list actors: %w", err)
}

msigExtractor := MultiSigActorExtractor{}
minerExtractor := StorageMinerExtractor{}
powerExtractor := StoragePowerExtractor{}

Expand Down Expand Up @@ -106,7 +108,18 @@ func (p *GenesisProcessor) ProcessGenesis(ctx context.Context, gen *types.TipSet
case builtin.PaymentChannelActorCodeID:
// TODO
case builtin.MultisigActorCodeID:
// TODO
res, err := msigExtractor.Extract(ctx, ActorInfo{
Actor: *genesisAct,
Address: addr,
ParentStateRoot: gen.ParentState(),
Epoch: gen.Height(),
TipSet: gen.Key(),
ParentTipSet: gen.Parents(),
}, p.node)
if err != nil {
return xerrors.Errorf("multisig actor state: %w", err)
}
result.AddMsig(res.(multisigmodel.MultisigTransactionList))
case builtin.RewardActorCodeID:
// TODO
case builtin.VerifiedRegistryActorCodeID:
Expand Down
Loading

0 comments on commit b9d469c

Please sign in to comment.