Skip to content

Commit

Permalink
Merge pull request #10058 from filecoin-project/jen/mergetx
Browse files Browse the repository at this point in the history
backport: #10055 #10053
  • Loading branch information
jennijuju authored Jan 19, 2023
2 parents 0afc38c + f2561e5 commit 6915023
Show file tree
Hide file tree
Showing 14 changed files with 428 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ type FullNode interface {
EthGetBlockByNumber(ctx context.Context, blkNum string, fullTxInfo bool) (ethtypes.EthBlock, error) //perm:read
EthGetTransactionByHash(ctx context.Context, txHash *ethtypes.EthHash) (*ethtypes.EthTx, error) //perm:read
EthGetTransactionHashByCid(ctx context.Context, cid cid.Cid) (*ethtypes.EthHash, error) //perm:read
EthGetMessageCidByTransactionHash(ctx context.Context, txHash *ethtypes.EthHash) (*cid.Cid, error) //perm:read
EthGetTransactionCount(ctx context.Context, sender ethtypes.EthAddress, blkOpt string) (ethtypes.EthUint64, error) //perm:read
EthGetTransactionReceipt(ctx context.Context, txHash ethtypes.EthHash) (*EthTxReceipt, error) //perm:read
EthGetTransactionByBlockHashAndIndex(ctx context.Context, blkHash ethtypes.EthHash, txIndex ethtypes.EthUint64) (ethtypes.EthTx, error) //perm:read
Expand Down
15 changes: 15 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions chain/store/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)

const TIPSETKEY_BACKFILL_RANGE = 2 * build.Finality

func (cs *ChainStore) UnionStore() bstore.Blockstore {
return bstore.Union(cs.stateBlockstore, cs.chainBlockstore)
}
Expand Down Expand Up @@ -113,6 +115,20 @@ func (cs *ChainStore) Import(ctx context.Context, r io.Reader) (*types.TipSet, e
return nil, xerrors.Errorf("failed to load root tipset from chainfile: %w", err)
}

ts := root
for i := 0; i < int(TIPSETKEY_BACKFILL_RANGE); i++ {
err = cs.PersistTipset(ctx, ts)
if err != nil {
return nil, err
}
parentTsKey := ts.Parents()
ts, err = cs.LoadTipSet(ctx, parentTsKey)
if ts == nil || err != nil {
log.Warnf("Only able to load the last %d tipsets", i)
break
}
}

return root, nil
}

Expand Down
4 changes: 4 additions & 0 deletions chain/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,10 @@ func (cs *ChainStore) StateBlockstore() bstore.Blockstore {
return cs.stateBlockstore
}

func (cs *ChainStore) ChainLocalBlockstore() bstore.Blockstore {
return cs.chainLocalBlockstore
}

func ActorStore(ctx context.Context, bs bstore.Blockstore) adt.Store {
return adt.WrapStore(ctx, cbor.NewCborStore(bs))
}
Expand Down
46 changes: 46 additions & 0 deletions chain/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/ipfs/go-datastore"
"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
Expand Down Expand Up @@ -124,6 +125,51 @@ func TestChainExportImport(t *testing.T) {
}
}

// Test to check if tipset key cids are being stored on snapshot
func TestChainImportTipsetKeyCid(t *testing.T) {

ctx := context.Background()
cg, err := gen.NewGenerator()
require.NoError(t, err)

buf := new(bytes.Buffer)
var last *types.TipSet
var tsKeys []types.TipSetKey
for i := 0; i < 10; i++ {
ts, err := cg.NextTipSet()
require.NoError(t, err)
last = ts.TipSet.TipSet()
tsKeys = append(tsKeys, last.Key())
}

if err := cg.ChainStore().Export(ctx, last, last.Height(), false, buf); err != nil {
t.Fatal(err)
}

nbs := blockstore.NewMemorySync()
cs := store.NewChainStore(nbs, nbs, datastore.NewMapDatastore(), filcns.Weight, nil)
defer cs.Close() //nolint:errcheck

root, err := cs.Import(ctx, buf)
require.NoError(t, err)

require.Truef(t, root.Equals(last), "imported chain differed from exported chain")

err = cs.SetHead(ctx, last)
require.NoError(t, err)

for _, tsKey := range tsKeys {
_, err := cs.LoadTipSet(ctx, tsKey)
require.NoError(t, err)

tsCid, err := tsKey.Cid()
require.NoError(t, err)
_, err = cs.ChainLocalBlockstore().Get(ctx, tsCid)
require.NoError(t, err)

}
}

func TestChainExportImportFull(t *testing.T) {
//stm: @CHAIN_GEN_NEXT_TIPSET_001
//stm: @CHAIN_STORE_IMPORT_001, @CHAIN_STORE_EXPORT_001, @CHAIN_STORE_SET_HEAD_001
Expand Down
20 changes: 20 additions & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
* [EthGetFilterChanges](#EthGetFilterChanges)
* [EthGetFilterLogs](#EthGetFilterLogs)
* [EthGetLogs](#EthGetLogs)
* [EthGetMessageCidByTransactionHash](#EthGetMessageCidByTransactionHash)
* [EthGetStorageAt](#EthGetStorageAt)
* [EthGetTransactionByBlockHashAndIndex](#EthGetTransactionByBlockHashAndIndex)
* [EthGetTransactionByBlockNumberAndIndex](#EthGetTransactionByBlockNumberAndIndex)
Expand Down Expand Up @@ -2641,6 +2642,25 @@ Response:
]
```

### EthGetMessageCidByTransactionHash


Perms: read

Inputs:
```json
[
"0x37690cfec6c1bf4c3b9288c7a5d783e98731e90b0a4c177c2a374c7a9427355e"
]
```

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### EthGetStorageAt


Expand Down
Loading

0 comments on commit 6915023

Please sign in to comment.