Add putObj and putMany to apiBlockstore

This commit is contained in:
Geoff Stuart 2022-06-08 12:50:27 -04:00
parent 81cacd76a7
commit 5c0f2c8ae6
20 changed files with 292 additions and 7701 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"time" "time"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
@ -38,6 +39,8 @@ import (
type ChainIO interface { type ChainIO interface {
ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainHasObj(context.Context, cid.Cid) (bool, error) ChainHasObj(context.Context, cid.Cid) (bool, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
} }
const LookbackNoLimit = abi.ChainEpoch(-1) const LookbackNoLimit = abi.ChainEpoch(-1)
@ -123,6 +126,12 @@ type FullNode interface {
// ChainHasObj checks if a given CID exists in the chain blockstore. // ChainHasObj checks if a given CID exists in the chain blockstore.
ChainHasObj(context.Context, cid.Cid) (bool, error) //perm:read ChainHasObj(context.Context, cid.Cid) (bool, error) //perm:read
// ChainPutObj puts a given object into the block store
ChainPutObj(context.Context, blocks.Block) error //perm:admin
// ChainPutMany puts a given array of objects into the block store
ChainPutMany(context.Context, []blocks.Block) error //perm:admin
// ChainStatObj returns statistics about the graph referenced by 'obj'. // ChainStatObj returns statistics about the graph referenced by 'obj'.
// If 'base' is also specified, then the returned stat will be a diff // If 'base' is also specified, then the returned stat will be a diff
// between the two objects. // between the two objects.

View File

@ -3,6 +3,7 @@ package api
import ( import (
"context" "context"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
@ -30,6 +31,8 @@ import (
type Gateway interface { type Gateway interface {
ChainHasObj(context.Context, cid.Cid) (bool, error) ChainHasObj(context.Context, cid.Cid) (bool, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
ChainHead(ctx context.Context) (*types.TipSet, error) ChainHead(ctx context.Context) (*types.TipSet, error)
ChainGetParentMessages(context.Context, cid.Cid) ([]Message, error) ChainGetParentMessages(context.Context, cid.Cid) ([]Message, error)
ChainGetParentReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error) ChainGetParentReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error)

View File

@ -28,6 +28,7 @@ import (
filestore "github.com/filecoin-project/go-fil-markets/filestore" filestore "github.com/filecoin-project/go-fil-markets/filestore"
"github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-jsonrpc/auth" "github.com/filecoin-project/go-jsonrpc/auth"
blocks "github.com/ipfs/go-block-format"
textselector "github.com/ipld/go-ipld-selector-text-lite" textselector "github.com/ipld/go-ipld-selector-text-lite"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
@ -95,6 +96,9 @@ func init() {
apiSelExample := api.Selector("Links/21/Hash/Links/42/Hash") apiSelExample := api.Selector("Links/21/Hash/Links/42/Hash")
clientEvent := retrievalmarket.ClientEventDealAccepted clientEvent := retrievalmarket.ClientEventDealAccepted
block := blocks.Block(&blocks.BasicBlock{})
ExampleValues[reflect.TypeOf(&block).Elem()] = block
addExample(bitfield.NewFromSet([]uint64{5})) addExample(bitfield.NewFromSet([]uint64{5}))
addExample(abi.RegisteredSealProof_StackedDrg32GiBV1_1) addExample(abi.RegisteredSealProof_StackedDrg32GiBV1_1)
addExample(abi.RegisteredPoStProof_StackedDrgWindow32GiBV1) addExample(abi.RegisteredPoStProof_StackedDrgWindow32GiBV1)

View File

@ -31,6 +31,7 @@ import (
imports "github.com/filecoin-project/lotus/node/repo/imports" imports "github.com/filecoin-project/lotus/node/repo/imports"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
uuid "github.com/google/uuid" uuid "github.com/google/uuid"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
metrics "github.com/libp2p/go-libp2p-core/metrics" metrics "github.com/libp2p/go-libp2p-core/metrics"
network0 "github.com/libp2p/go-libp2p-core/network" network0 "github.com/libp2p/go-libp2p-core/network"
@ -374,6 +375,34 @@ func (mr *MockFullNodeMockRecorder) ChainNotify(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainNotify", reflect.TypeOf((*MockFullNode)(nil).ChainNotify), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainNotify", reflect.TypeOf((*MockFullNode)(nil).ChainNotify), arg0)
} }
// ChainPutMany mocks base method.
func (m *MockFullNode) ChainPutMany(arg0 context.Context, arg1 []blocks.Block) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ChainPutMany", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// ChainPutMany indicates an expected call of ChainPutMany.
func (mr *MockFullNodeMockRecorder) ChainPutMany(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainPutMany", reflect.TypeOf((*MockFullNode)(nil).ChainPutMany), arg0, arg1)
}
// ChainPutObj mocks base method.
func (m *MockFullNode) ChainPutObj(arg0 context.Context, arg1 blocks.Block) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ChainPutObj", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// ChainPutObj indicates an expected call of ChainPutObj.
func (mr *MockFullNodeMockRecorder) ChainPutObj(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainPutObj", reflect.TypeOf((*MockFullNode)(nil).ChainPutObj), arg0, arg1)
}
// ChainReadObj mocks base method. // ChainReadObj mocks base method.
func (m *MockFullNode) ChainReadObj(arg0 context.Context, arg1 cid.Cid) ([]byte, error) { func (m *MockFullNode) ChainReadObj(arg0 context.Context, arg1 cid.Cid) ([]byte, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View File

@ -34,6 +34,7 @@ import (
"github.com/filecoin-project/lotus/node/repo/imports" "github.com/filecoin-project/lotus/node/repo/imports"
"github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/specs-storage/storage"
"github.com/google/uuid" "github.com/google/uuid"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
metrics "github.com/libp2p/go-libp2p-core/metrics" metrics "github.com/libp2p/go-libp2p-core/metrics"
"github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/network"
@ -48,6 +49,10 @@ type ChainIOStruct struct {
Internal struct { Internal struct {
ChainHasObj func(p0 context.Context, p1 cid.Cid) (bool, error) `` ChainHasObj func(p0 context.Context, p1 cid.Cid) (bool, error) ``
ChainPutMany func(p0 context.Context, p1 []blocks.Block) error ``
ChainPutObj func(p0 context.Context, p1 blocks.Block) error ``
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `` ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) ``
} }
} }
@ -141,6 +146,10 @@ type FullNodeStruct struct {
ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) `perm:"read"` ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) `perm:"read"`
ChainPutMany func(p0 context.Context, p1 []blocks.Block) error `perm:"admin"`
ChainPutObj func(p0 context.Context, p1 blocks.Block) error `perm:"admin"`
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `perm:"read"` ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `perm:"read"`
ChainSetHead func(p0 context.Context, p1 types.TipSetKey) error `perm:"admin"` ChainSetHead func(p0 context.Context, p1 types.TipSetKey) error `perm:"admin"`
@ -511,6 +520,10 @@ type GatewayStruct struct {
ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) `` ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) ``
ChainPutMany func(p0 context.Context, p1 []blocks.Block) error ``
ChainPutObj func(p0 context.Context, p1 blocks.Block) error ``
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `` ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) ``
GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) `` GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) ``
@ -977,6 +990,28 @@ func (s *ChainIOStub) ChainHasObj(p0 context.Context, p1 cid.Cid) (bool, error)
return false, ErrNotSupported return false, ErrNotSupported
} }
func (s *ChainIOStruct) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
if s.Internal.ChainPutMany == nil {
return ErrNotSupported
}
return s.Internal.ChainPutMany(p0, p1)
}
func (s *ChainIOStub) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
return ErrNotSupported
}
func (s *ChainIOStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
if s.Internal.ChainPutObj == nil {
return ErrNotSupported
}
return s.Internal.ChainPutObj(p0, p1)
}
func (s *ChainIOStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
return ErrNotSupported
}
func (s *ChainIOStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { func (s *ChainIOStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) {
if s.Internal.ChainReadObj == nil { if s.Internal.ChainReadObj == nil {
return *new([]byte), ErrNotSupported return *new([]byte), ErrNotSupported
@ -1307,6 +1342,28 @@ func (s *FullNodeStub) ChainNotify(p0 context.Context) (<-chan []*HeadChange, er
return nil, ErrNotSupported return nil, ErrNotSupported
} }
func (s *FullNodeStruct) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
if s.Internal.ChainPutMany == nil {
return ErrNotSupported
}
return s.Internal.ChainPutMany(p0, p1)
}
func (s *FullNodeStub) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
return ErrNotSupported
}
func (s *FullNodeStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
if s.Internal.ChainPutObj == nil {
return ErrNotSupported
}
return s.Internal.ChainPutObj(p0, p1)
}
func (s *FullNodeStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
return ErrNotSupported
}
func (s *FullNodeStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { func (s *FullNodeStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) {
if s.Internal.ChainReadObj == nil { if s.Internal.ChainReadObj == nil {
return *new([]byte), ErrNotSupported return *new([]byte), ErrNotSupported
@ -3287,6 +3344,28 @@ func (s *GatewayStub) ChainNotify(p0 context.Context) (<-chan []*HeadChange, err
return nil, ErrNotSupported return nil, ErrNotSupported
} }
func (s *GatewayStruct) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
if s.Internal.ChainPutMany == nil {
return ErrNotSupported
}
return s.Internal.ChainPutMany(p0, p1)
}
func (s *GatewayStub) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
return ErrNotSupported
}
func (s *GatewayStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
if s.Internal.ChainPutObj == nil {
return ErrNotSupported
}
return s.Internal.ChainPutObj(p0, p1)
}
func (s *GatewayStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
return ErrNotSupported
}
func (s *GatewayStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { func (s *GatewayStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) {
if s.Internal.ChainReadObj == nil { if s.Internal.ChainReadObj == nil {
return *new([]byte), ErrNotSupported return *new([]byte), ErrNotSupported

View File

@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/dline"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
textselector "github.com/ipld/go-ipld-selector-text-lite" textselector "github.com/ipld/go-ipld-selector-text-lite"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
@ -110,6 +111,12 @@ type FullNode interface {
// ChainDeleteObj deletes node referenced by the given CID // ChainDeleteObj deletes node referenced by the given CID
ChainDeleteObj(context.Context, cid.Cid) error //perm:admin ChainDeleteObj(context.Context, cid.Cid) error //perm:admin
// ChainPutObj puts and object into the blockstore
ChainPutObj(context.Context, blocks.Block) error
// ChainPutMany puts an array of objects into the blockstore
ChainPutMany(context.Context, []blocks.Block) error
// ChainHasObj checks if a given CID exists in the chain blockstore. // ChainHasObj checks if a given CID exists in the chain blockstore.
ChainHasObj(context.Context, cid.Cid) (bool, error) //perm:read ChainHasObj(context.Context, cid.Cid) (bool, error) //perm:read

View File

@ -3,6 +3,7 @@ package v0api
import ( import (
"context" "context"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
@ -34,6 +35,8 @@ import (
type Gateway interface { type Gateway interface {
ChainHasObj(context.Context, cid.Cid) (bool, error) ChainHasObj(context.Context, cid.Cid) (bool, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
ChainHead(ctx context.Context) (*types.TipSet, error) ChainHead(ctx context.Context) (*types.TipSet, error)
ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error) ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error)
ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error)

View File

@ -23,6 +23,7 @@ import (
marketevents "github.com/filecoin-project/lotus/markets/loggers" marketevents "github.com/filecoin-project/lotus/markets/loggers"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/repo/imports" "github.com/filecoin-project/lotus/node/repo/imports"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -74,6 +75,10 @@ type FullNodeStruct struct {
ChainNotify func(p0 context.Context) (<-chan []*api.HeadChange, error) `perm:"read"` ChainNotify func(p0 context.Context) (<-chan []*api.HeadChange, error) `perm:"read"`
ChainPutMany func(p0 context.Context, p1 []blocks.Block) error ``
ChainPutObj func(p0 context.Context, p1 blocks.Block) error ``
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `perm:"read"` ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `perm:"read"`
ChainSetHead func(p0 context.Context, p1 types.TipSetKey) error `perm:"admin"` ChainSetHead func(p0 context.Context, p1 types.TipSetKey) error `perm:"admin"`
@ -420,6 +425,10 @@ type GatewayStruct struct {
ChainNotify func(p0 context.Context) (<-chan []*api.HeadChange, error) `` ChainNotify func(p0 context.Context) (<-chan []*api.HeadChange, error) ``
ChainPutMany func(p0 context.Context, p1 []blocks.Block) error ``
ChainPutObj func(p0 context.Context, p1 blocks.Block) error ``
ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `` ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) ``
GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *api.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) `` GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *api.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) ``
@ -682,6 +691,28 @@ func (s *FullNodeStub) ChainNotify(p0 context.Context) (<-chan []*api.HeadChange
return nil, ErrNotSupported return nil, ErrNotSupported
} }
func (s *FullNodeStruct) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
if s.Internal.ChainPutMany == nil {
return ErrNotSupported
}
return s.Internal.ChainPutMany(p0, p1)
}
func (s *FullNodeStub) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
return ErrNotSupported
}
func (s *FullNodeStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
if s.Internal.ChainPutObj == nil {
return ErrNotSupported
}
return s.Internal.ChainPutObj(p0, p1)
}
func (s *FullNodeStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
return ErrNotSupported
}
func (s *FullNodeStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { func (s *FullNodeStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) {
if s.Internal.ChainReadObj == nil { if s.Internal.ChainReadObj == nil {
return *new([]byte), ErrNotSupported return *new([]byte), ErrNotSupported
@ -2530,6 +2561,28 @@ func (s *GatewayStub) ChainNotify(p0 context.Context) (<-chan []*api.HeadChange,
return nil, ErrNotSupported return nil, ErrNotSupported
} }
func (s *GatewayStruct) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
if s.Internal.ChainPutMany == nil {
return ErrNotSupported
}
return s.Internal.ChainPutMany(p0, p1)
}
func (s *GatewayStub) ChainPutMany(p0 context.Context, p1 []blocks.Block) error {
return ErrNotSupported
}
func (s *GatewayStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
if s.Internal.ChainPutObj == nil {
return ErrNotSupported
}
return s.Internal.ChainPutObj(p0, p1)
}
func (s *GatewayStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error {
return ErrNotSupported
}
func (s *GatewayStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { func (s *GatewayStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) {
if s.Internal.ChainReadObj == nil { if s.Internal.ChainReadObj == nil {
return *new([]byte), ErrNotSupported return *new([]byte), ErrNotSupported

View File

@ -33,6 +33,7 @@ import (
imports "github.com/filecoin-project/lotus/node/repo/imports" imports "github.com/filecoin-project/lotus/node/repo/imports"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
uuid "github.com/google/uuid" uuid "github.com/google/uuid"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
metrics "github.com/libp2p/go-libp2p-core/metrics" metrics "github.com/libp2p/go-libp2p-core/metrics"
network0 "github.com/libp2p/go-libp2p-core/network" network0 "github.com/libp2p/go-libp2p-core/network"
@ -377,6 +378,34 @@ func (mr *MockFullNodeMockRecorder) ChainNotify(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainNotify", reflect.TypeOf((*MockFullNode)(nil).ChainNotify), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainNotify", reflect.TypeOf((*MockFullNode)(nil).ChainNotify), arg0)
} }
// ChainPutMany mocks base method.
func (m *MockFullNode) ChainPutMany(arg0 context.Context, arg1 []blocks.Block) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ChainPutMany", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// ChainPutMany indicates an expected call of ChainPutMany.
func (mr *MockFullNodeMockRecorder) ChainPutMany(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainPutMany", reflect.TypeOf((*MockFullNode)(nil).ChainPutMany), arg0, arg1)
}
// ChainPutObj mocks base method.
func (m *MockFullNode) ChainPutObj(arg0 context.Context, arg1 blocks.Block) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ChainPutObj", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// ChainPutObj indicates an expected call of ChainPutObj.
func (mr *MockFullNodeMockRecorder) ChainPutObj(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainPutObj", reflect.TypeOf((*MockFullNode)(nil).ChainPutObj), arg0, arg1)
}
// ChainReadObj mocks base method. // ChainReadObj mocks base method.
func (m *MockFullNode) ChainReadObj(arg0 context.Context, arg1 cid.Cid) ([]byte, error) { func (m *MockFullNode) ChainReadObj(arg0 context.Context, arg1 cid.Cid) ([]byte, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View File

@ -11,6 +11,8 @@ import (
type ChainIO interface { type ChainIO interface {
ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainHasObj(context.Context, cid.Cid) (bool, error) ChainHasObj(context.Context, cid.Cid) (bool, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
} }
type apiBlockstore struct { type apiBlockstore struct {
@ -49,12 +51,12 @@ func (a *apiBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) {
return len(bb), nil return len(bb), nil
} }
func (a *apiBlockstore) Put(context.Context, blocks.Block) error { func (a *apiBlockstore) Put(ctx context.Context, block blocks.Block) error {
return xerrors.New("not supported") return a.api.ChainPutObj(ctx, block)
} }
func (a *apiBlockstore) PutMany(context.Context, []blocks.Block) error { func (a *apiBlockstore) PutMany(ctx context.Context, blocks []blocks.Block) error {
return xerrors.New("not supported") return a.api.ChainPutMany(ctx, blocks)
} }
func (a *apiBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { func (a *apiBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,6 +4,8 @@ import (
"context" "context"
"sync" "sync"
blocks "github.com/ipfs/go-block-format"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
@ -39,6 +41,14 @@ func (m *MockAPI) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) {
return blk.RawData(), nil return blk.RawData(), nil
} }
func (m *MockAPI) ChainPutObj(ctx context.Context, block blocks.Block) error {
return m.bs.Put(ctx, block)
}
func (m *MockAPI) ChainPutMany(ctx context.Context, blocks []blocks.Block) error {
return m.bs.PutMany(ctx, blocks)
}
func (m *MockAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) { func (m *MockAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) {
m.lk.Lock() m.lk.Lock()
defer m.lk.Unlock() defer m.lk.Unlock()

View File

@ -29,6 +29,8 @@
* [ChainHasObj](#ChainHasObj) * [ChainHasObj](#ChainHasObj)
* [ChainHead](#ChainHead) * [ChainHead](#ChainHead)
* [ChainNotify](#ChainNotify) * [ChainNotify](#ChainNotify)
* [ChainPutMany](#ChainPutMany)
* [ChainPutObj](#ChainPutObj)
* [ChainReadObj](#ChainReadObj) * [ChainReadObj](#ChainReadObj)
* [ChainSetHead](#ChainSetHead) * [ChainSetHead](#ChainSetHead)
* [ChainStatObj](#ChainStatObj) * [ChainStatObj](#ChainStatObj)
@ -971,6 +973,38 @@ Response:
] ]
``` ```
### ChainPutMany
ChainPutMany puts an array of objects into the blockstore
Perms:
Inputs:
```json
[
[
{}
]
]
```
Response: `{}`
### ChainPutObj
ChainPutObj puts and object into the blockstore
Perms:
Inputs:
```json
[
{}
]
```
Response: `{}`
### ChainReadObj ### ChainReadObj
ChainReadObj reads ipld nodes referenced by the specified CID from chain ChainReadObj reads ipld nodes referenced by the specified CID from chain
blockstore and returns raw bytes. blockstore and returns raw bytes.

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"time" "time"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -46,6 +47,8 @@ type TargetAPI interface {
ChainNotify(context.Context) (<-chan []*api.HeadChange, error) ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error) ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error)
ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
ChainGetGenesis(context.Context) (*types.TipSet, error) ChainGetGenesis(context.Context) (*types.TipSet, error)
GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error)
MpoolPushUntrusted(ctx context.Context, sm *types.SignedMessage) (cid.Cid, error) MpoolPushUntrusted(ctx context.Context, sm *types.SignedMessage) (cid.Cid, error)
@ -251,6 +254,14 @@ func (gw *Node) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) {
return gw.target.ChainReadObj(ctx, c) return gw.target.ChainReadObj(ctx, c)
} }
func (gw *Node) ChainPutObj(ctx context.Context, block blocks.Block) error {
return gw.target.ChainPutObj(ctx, block)
}
func (gw *Node) ChainPutMany(ctx context.Context, blocks []blocks.Block) error {
return gw.target.ChainPutMany(ctx, blocks)
}
func (gw *Node) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) { func (gw *Node) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) {
if err := gw.checkTipsetKey(ctx, tsk); err != nil { if err := gw.checkTipsetKey(ctx, tsk); err != nil {
return nil, err return nil, err

View File

@ -3,6 +3,7 @@ package storageadapter
import ( import (
"context" "context"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor" cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -20,6 +21,8 @@ type apiWrapper struct {
StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error)
ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainHasObj(context.Context, cid.Cid) (bool, error) ChainHasObj(context.Context, cid.Cid) (bool, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
} }
} }

View File

@ -15,6 +15,7 @@ import (
"go.uber.org/fx" "go.uber.org/fx"
"golang.org/x/xerrors" "golang.org/x/xerrors"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-blockservice" "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
offline "github.com/ipfs/go-ipfs-exchange-offline" offline "github.com/ipfs/go-ipfs-exchange-offline"
@ -261,6 +262,14 @@ func (m *ChainModule) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, er
return blk.RawData(), nil return blk.RawData(), nil
} }
func (a *ChainAPI) ChainPutObj(ctx context.Context, obj blocks.Block) error {
return a.ExposedBlockstore.Put(ctx, obj)
}
func (a *ChainAPI) ChainPutMany(ctx context.Context, objs []blocks.Block) error {
return a.ExposedBlockstore.PutMany(ctx, objs)
}
func (a *ChainAPI) ChainDeleteObj(ctx context.Context, obj cid.Cid) error { func (a *ChainAPI) ChainDeleteObj(ctx context.Context, obj cid.Cid) error {
return a.ExposedBlockstore.DeleteBlock(ctx, obj) return a.ExposedBlockstore.DeleteBlock(ctx, obj)
} }

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-bitfield"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
@ -122,6 +123,8 @@ type fullNodeFilteredAPI interface {
ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error) ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error)
ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainHasObj(context.Context, cid.Cid) (bool, error) ChainHasObj(context.Context, cid.Cid) (bool, error)
ChainPutObj(context.Context, blocks.Block) error
ChainPutMany(context.Context, []blocks.Block) error
ChainGetTipSet(ctx context.Context, key types.TipSetKey) (*types.TipSet, error) ChainGetTipSet(ctx context.Context, key types.TipSetKey) (*types.TipSet, error)
WalletSign(context.Context, address.Address, []byte) (*crypto.Signature, error) WalletSign(context.Context, address.Address, []byte) (*crypto.Signature, error)