Fix even more lint warnings
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
c6b6c2990c
commit
5605aae269
@ -37,6 +37,10 @@ issues:
|
|||||||
- path: build/params_.*\.go
|
- path: build/params_.*\.go
|
||||||
linters:
|
linters:
|
||||||
- golint
|
- golint
|
||||||
|
|
||||||
|
- path: api/apistruct/struct.go
|
||||||
|
linters:
|
||||||
|
- golint
|
||||||
|
|
||||||
- path: .*_test.go
|
- path: .*_test.go
|
||||||
linters:
|
linters:
|
||||||
|
@ -193,8 +193,7 @@ func (v *Visitor) Visit(node ast.Node) ast.Visitor {
|
|||||||
|
|
||||||
const noComment = "There are not yet any comments for this method."
|
const noComment = "There are not yet any comments for this method."
|
||||||
|
|
||||||
func parseApiASTInfo() (map[string]string, map[string]string) {
|
func parseApiASTInfo() (map[string]string, map[string]string) { //nolint:golint
|
||||||
|
|
||||||
fset := token.NewFileSet()
|
fset := token.NewFileSet()
|
||||||
pkgs, err := parser.ParseDir(fset, "./api", nil, parser.AllErrors|parser.ParseComments)
|
pkgs, err := parser.ParseDir(fset, "./api", nil, parser.AllErrors|parser.ParseComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,7 +35,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, carExport bool) {
|
func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, carExport bool) {
|
||||||
os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
n, sn := b(t, 1, oneMiner)
|
n, sn := b(t, 1, oneMiner)
|
||||||
@ -72,7 +72,7 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, carExport
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDoubleDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
func TestDoubleDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
n, sn := b(t, 1, oneMiner)
|
n, sn := b(t, 1, oneMiner)
|
||||||
|
@ -82,7 +82,7 @@ func (ts *testSuite) testMiningReal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExport bool) {
|
func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExport bool) {
|
||||||
os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
|
|
||||||
// test making a deal with a fresh miner, and see if it starts to mine
|
// test making a deal with a fresh miner, and see if it starts to mine
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func (ve Version) EqMajorMinor(v2 Version) bool {
|
|||||||
// APIVersion is a semver version of the rpc api exposed
|
// APIVersion is a semver version of the rpc api exposed
|
||||||
var APIVersion Version = newVer(0, 3, 0)
|
var APIVersion Version = newVer(0, 3, 0)
|
||||||
|
|
||||||
//nolint:varcheck
|
//nolint:varcheck,deadcode
|
||||||
const (
|
const (
|
||||||
majorMask = 0xff0000
|
majorMask = 0xff0000
|
||||||
minorMask = 0xffff00
|
minorMask = 0xffff00
|
||||||
|
@ -561,26 +561,30 @@ func (bpt *bsPeerTracker) logSuccess(p peer.ID, dur time.Duration) {
|
|||||||
bpt.lk.Lock()
|
bpt.lk.Lock()
|
||||||
defer bpt.lk.Unlock()
|
defer bpt.lk.Unlock()
|
||||||
|
|
||||||
if pi, ok := bpt.peers[p]; !ok {
|
var pi *peerStats
|
||||||
|
var ok bool
|
||||||
|
if pi, ok = bpt.peers[p]; !ok {
|
||||||
log.Warnw("log success called on peer not in tracker", "peerid", p.String())
|
log.Warnw("log success called on peer not in tracker", "peerid", p.String())
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
pi.successes++
|
|
||||||
|
|
||||||
logTime(pi, dur)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pi.successes++
|
||||||
|
logTime(pi, dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bpt *bsPeerTracker) logFailure(p peer.ID, dur time.Duration) {
|
func (bpt *bsPeerTracker) logFailure(p peer.ID, dur time.Duration) {
|
||||||
bpt.lk.Lock()
|
bpt.lk.Lock()
|
||||||
defer bpt.lk.Unlock()
|
defer bpt.lk.Unlock()
|
||||||
if pi, ok := bpt.peers[p]; !ok {
|
|
||||||
|
var pi *peerStats
|
||||||
|
var ok bool
|
||||||
|
if pi, ok = bpt.peers[p]; !ok {
|
||||||
log.Warn("log failure called on peer not in tracker", "peerid", p.String())
|
log.Warn("log failure called on peer not in tracker", "peerid", p.String())
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
pi.failures++
|
|
||||||
logTime(pi, dur)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pi.failures++
|
||||||
|
logTime(pi, dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bpt *bsPeerTracker) removePeer(p peer.ID) {
|
func (bpt *bsPeerTracker) removePeer(p peer.ID) {
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
var log = logging.Logger("events")
|
var log = logging.Logger("events")
|
||||||
|
|
||||||
// `curH`-`ts.Height` = `confidence`
|
// HeightHandler `curH`-`ts.Height` = `confidence`
|
||||||
type HeightHandler func(ctx context.Context, ts *types.TipSet, curH abi.ChainEpoch) error
|
type HeightHandler func(ctx context.Context, ts *types.TipSet, curH abi.ChainEpoch) error
|
||||||
type RevertHandler func(ctx context.Context, ts *types.TipSet) error
|
type RevertHandler func(ctx context.Context, ts *types.TipSet) error
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ type heightHandler struct {
|
|||||||
revert RevertHandler
|
revert RevertHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
type eventApi interface {
|
type eventAPI interface {
|
||||||
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
|
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
|
||||||
ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error)
|
ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error)
|
||||||
ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error)
|
ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error)
|
||||||
@ -42,7 +42,7 @@ type eventApi interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Events struct {
|
type Events struct {
|
||||||
api eventApi
|
api eventAPI
|
||||||
|
|
||||||
tsc *tipSetCache
|
tsc *tipSetCache
|
||||||
lk sync.Mutex
|
lk sync.Mutex
|
||||||
@ -54,7 +54,7 @@ type Events struct {
|
|||||||
calledEvents
|
calledEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEvents(ctx context.Context, api eventApi) *Events {
|
func NewEvents(ctx context.Context, api eventAPI) *Events {
|
||||||
gcConfidence := 2 * build.ForkLengthThreshold
|
gcConfidence := 2 * build.ForkLengthThreshold
|
||||||
|
|
||||||
tsc := newTSCache(gcConfidence, api.ChainGetTipSetByHeight)
|
tsc := newTSCache(gcConfidence, api.ChainGetTipSetByHeight)
|
||||||
@ -82,9 +82,9 @@ func NewEvents(ctx context.Context, api eventApi) *Events {
|
|||||||
|
|
||||||
confQueue: map[triggerH]map[msgH][]*queuedEvent{},
|
confQueue: map[triggerH]map[msgH][]*queuedEvent{},
|
||||||
revertQueue: map[msgH][]triggerH{},
|
revertQueue: map[msgH][]triggerH{},
|
||||||
triggers: map[triggerId]*callHandler{},
|
triggers: map[triggerID]*callHandler{},
|
||||||
matchers: map[triggerId][]MatchFunc{},
|
matchers: map[triggerID][]MatchFunc{},
|
||||||
timeouts: map[abi.ChainEpoch]map[triggerId]int{},
|
timeouts: map[abi.ChainEpoch]map[triggerID]int{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
const NoTimeout = math.MaxInt64
|
const NoTimeout = math.MaxInt64
|
||||||
|
|
||||||
type triggerId = uint64
|
type triggerID = uint64
|
||||||
|
|
||||||
// msgH is the block height at which a message was present / event has happened
|
// msgH is the block height at which a message was present / event has happened
|
||||||
type msgH = abi.ChainEpoch
|
type msgH = abi.ChainEpoch
|
||||||
@ -23,6 +23,7 @@ type msgH = abi.ChainEpoch
|
|||||||
// message (msgH+confidence)
|
// message (msgH+confidence)
|
||||||
type triggerH = abi.ChainEpoch
|
type triggerH = abi.ChainEpoch
|
||||||
|
|
||||||
|
// CalledHandler
|
||||||
// `ts` is the tipset, in which the `msg` is included.
|
// `ts` is the tipset, in which the `msg` is included.
|
||||||
// `curH`-`ts.Height` = `confidence`
|
// `curH`-`ts.Height` = `confidence`
|
||||||
type CalledHandler func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error)
|
type CalledHandler func(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error)
|
||||||
@ -48,7 +49,7 @@ type callHandler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type queuedEvent struct {
|
type queuedEvent struct {
|
||||||
trigger triggerId
|
trigger triggerID
|
||||||
|
|
||||||
h abi.ChainEpoch
|
h abi.ChainEpoch
|
||||||
msg *types.Message
|
msg *types.Message
|
||||||
@ -57,7 +58,7 @@ type queuedEvent struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type calledEvents struct {
|
type calledEvents struct {
|
||||||
cs eventApi
|
cs eventAPI
|
||||||
tsc *tipSetCache
|
tsc *tipSetCache
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
gcConfidence uint64
|
gcConfidence uint64
|
||||||
@ -66,10 +67,10 @@ type calledEvents struct {
|
|||||||
|
|
||||||
lk sync.Mutex
|
lk sync.Mutex
|
||||||
|
|
||||||
ctr triggerId
|
ctr triggerID
|
||||||
|
|
||||||
triggers map[triggerId]*callHandler
|
triggers map[triggerID]*callHandler
|
||||||
matchers map[triggerId][]MatchFunc
|
matchers map[triggerID][]MatchFunc
|
||||||
|
|
||||||
// maps block heights to events
|
// maps block heights to events
|
||||||
// [triggerH][msgH][event]
|
// [triggerH][msgH][event]
|
||||||
@ -78,8 +79,8 @@ type calledEvents struct {
|
|||||||
// [msgH][triggerH]
|
// [msgH][triggerH]
|
||||||
revertQueue map[msgH][]triggerH
|
revertQueue map[msgH][]triggerH
|
||||||
|
|
||||||
// [timeoutH+confidence][triggerId]{calls}
|
// [timeoutH+confidence][triggerID]{calls}
|
||||||
timeouts map[abi.ChainEpoch]map[triggerId]int
|
timeouts map[abi.ChainEpoch]map[triggerID]int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *calledEvents) headChangeCalled(rev, app []*types.TipSet) error {
|
func (e *calledEvents) headChangeCalled(rev, app []*types.TipSet) error {
|
||||||
@ -157,8 +158,8 @@ func (e *calledEvents) checkNewCalls(ts *types.TipSet) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *calledEvents) queueForConfidence(triggerId uint64, msg *types.Message, ts *types.TipSet) {
|
func (e *calledEvents) queueForConfidence(trigID uint64, msg *types.Message, ts *types.TipSet) {
|
||||||
trigger := e.triggers[triggerId]
|
trigger := e.triggers[trigID]
|
||||||
|
|
||||||
appliedH := ts.Height()
|
appliedH := ts.Height()
|
||||||
|
|
||||||
@ -171,7 +172,7 @@ func (e *calledEvents) queueForConfidence(triggerId uint64, msg *types.Message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
byOrigH[appliedH] = append(byOrigH[appliedH], &queuedEvent{
|
byOrigH[appliedH] = append(byOrigH[appliedH], &queuedEvent{
|
||||||
trigger: triggerId,
|
trigger: trigID,
|
||||||
h: appliedH,
|
h: appliedH,
|
||||||
msg: msg,
|
msg: msg,
|
||||||
})
|
})
|
||||||
@ -231,11 +232,11 @@ func (e *calledEvents) applyTimeouts(ts *types.TipSet) {
|
|||||||
return // nothing to do
|
return // nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
for triggerId, calls := range triggers {
|
for triggerID, calls := range triggers {
|
||||||
if calls > 0 {
|
if calls > 0 {
|
||||||
continue // don't timeout if the method was called
|
continue // don't timeout if the method was called
|
||||||
}
|
}
|
||||||
trigger := e.triggers[triggerId]
|
trigger := e.triggers[triggerID]
|
||||||
if trigger.disabled {
|
if trigger.disabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,12 @@ type heightEvents struct {
|
|||||||
tsc *tipSetCache
|
tsc *tipSetCache
|
||||||
gcConfidence abi.ChainEpoch
|
gcConfidence abi.ChainEpoch
|
||||||
|
|
||||||
ctr triggerId
|
ctr triggerID
|
||||||
|
|
||||||
heightTriggers map[triggerId]*heightHandler
|
heightTriggers map[triggerID]*heightHandler
|
||||||
|
|
||||||
htTriggerHeights map[triggerH][]triggerId
|
htTriggerHeights map[triggerH][]triggerID
|
||||||
htHeights map[msgH][]triggerId
|
htHeights map[msgH][]triggerID
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ func (fcs *fakeCS) notifDone() {
|
|||||||
fcs.sync.Unlock()
|
fcs.sync.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ eventApi = &fakeCS{}
|
var _ eventAPI = &fakeCS{}
|
||||||
|
|
||||||
func TestAt(t *testing.T) {
|
func TestAt(t *testing.T) {
|
||||||
fcs := &fakeCS{
|
fcs := &fakeCS{
|
||||||
|
@ -431,7 +431,7 @@ func (cg *ChainGen) makeBlock(parents *types.TipSet, m address.Address, vrfticke
|
|||||||
return fblk, err
|
return fblk, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is awkward. It's used to deal with messages made when
|
// ResyncBankerNonce is used for dealing with messages made when
|
||||||
// simulating forks
|
// simulating forks
|
||||||
func (cg *ChainGen) ResyncBankerNonce(ts *types.TipSet) error {
|
func (cg *ChainGen) ResyncBankerNonce(ts *types.TipSet) error {
|
||||||
act, err := cg.sm.GetActor(cg.banker, ts)
|
act, err := cg.sm.GetActor(cg.banker, ts)
|
||||||
@ -538,13 +538,6 @@ func (wpp *wppProvider) ComputeProof(context.Context, []abi.SectorInfo, abi.PoSt
|
|||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProofInput struct {
|
|
||||||
sectors []abi.SectorInfo
|
|
||||||
hvrf []byte
|
|
||||||
challengedSectors []uint64
|
|
||||||
vrfout []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
||||||
miner address.Address, brand types.BeaconEntry, mbi *api.MiningBaseInfo, a MiningCheckAPI) (*types.ElectionProof, error) {
|
miner address.Address, brand types.BeaconEntry, mbi *api.MiningBaseInfo, a MiningCheckAPI) (*types.ElectionProof, error) {
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testMpoolApi struct {
|
type testMpoolAPI struct {
|
||||||
cb func(rev, app []*types.TipSet) error
|
cb func(rev, app []*types.TipSet) error
|
||||||
|
|
||||||
bmsgs map[cid.Cid][]*types.SignedMessage
|
bmsgs map[cid.Cid][]*types.SignedMessage
|
||||||
@ -25,68 +25,68 @@ type testMpoolApi struct {
|
|||||||
tipsets []*types.TipSet
|
tipsets []*types.TipSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestMpoolApi() *testMpoolApi {
|
func newTestMpoolApi() *testMpoolAPI {
|
||||||
return &testMpoolApi{
|
return &testMpoolAPI{
|
||||||
bmsgs: make(map[cid.Cid][]*types.SignedMessage),
|
bmsgs: make(map[cid.Cid][]*types.SignedMessage),
|
||||||
statenonce: make(map[address.Address]uint64),
|
statenonce: make(map[address.Address]uint64),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) applyBlock(t *testing.T, b *types.BlockHeader) {
|
func (tma *testMpoolAPI) applyBlock(t *testing.T, b *types.BlockHeader) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err := tma.cb(nil, []*types.TipSet{mock.TipSet(b)}); err != nil {
|
if err := tma.cb(nil, []*types.TipSet{mock.TipSet(b)}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) revertBlock(t *testing.T, b *types.BlockHeader) {
|
func (tma *testMpoolAPI) revertBlock(t *testing.T, b *types.BlockHeader) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err := tma.cb([]*types.TipSet{mock.TipSet(b)}, nil); err != nil {
|
if err := tma.cb([]*types.TipSet{mock.TipSet(b)}, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) setStateNonce(addr address.Address, v uint64) {
|
func (tma *testMpoolAPI) setStateNonce(addr address.Address, v uint64) {
|
||||||
tma.statenonce[addr] = v
|
tma.statenonce[addr] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) setBlockMessages(h *types.BlockHeader, msgs ...*types.SignedMessage) {
|
func (tma *testMpoolAPI) setBlockMessages(h *types.BlockHeader, msgs ...*types.SignedMessage) {
|
||||||
tma.bmsgs[h.Cid()] = msgs
|
tma.bmsgs[h.Cid()] = msgs
|
||||||
tma.tipsets = append(tma.tipsets, mock.TipSet(h))
|
tma.tipsets = append(tma.tipsets, mock.TipSet(h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) SubscribeHeadChanges(cb func(rev, app []*types.TipSet) error) *types.TipSet {
|
func (tma *testMpoolAPI) SubscribeHeadChanges(cb func(rev, app []*types.TipSet) error) *types.TipSet {
|
||||||
tma.cb = cb
|
tma.cb = cb
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) PutMessage(m types.ChainMsg) (cid.Cid, error) {
|
func (tma *testMpoolAPI) PutMessage(m types.ChainMsg) (cid.Cid, error) {
|
||||||
return cid.Undef, nil
|
return cid.Undef, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) PubSubPublish(string, []byte) error {
|
func (tma *testMpoolAPI) PubSubPublish(string, []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) StateGetActor(addr address.Address, ts *types.TipSet) (*types.Actor, error) {
|
func (tma *testMpoolAPI) StateGetActor(addr address.Address, ts *types.TipSet) (*types.Actor, error) {
|
||||||
return &types.Actor{
|
return &types.Actor{
|
||||||
Nonce: tma.statenonce[addr],
|
Nonce: tma.statenonce[addr],
|
||||||
Balance: types.NewInt(90000000),
|
Balance: types.NewInt(90000000),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) StateAccountKey(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
func (tma *testMpoolAPI) StateAccountKey(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
||||||
if addr.Protocol() != address.BLS && addr.Protocol() != address.SECP256K1 {
|
if addr.Protocol() != address.BLS && addr.Protocol() != address.SECP256K1 {
|
||||||
return address.Undef, fmt.Errorf("given address was not a key addr")
|
return address.Undef, fmt.Errorf("given address was not a key addr")
|
||||||
}
|
}
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
func (tma *testMpoolAPI) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
||||||
return nil, tma.bmsgs[h.Cid()], nil
|
return nil, tma.bmsgs[h.Cid()], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) MessagesForTipset(ts *types.TipSet) ([]types.ChainMsg, error) {
|
func (tma *testMpoolAPI) MessagesForTipset(ts *types.TipSet) ([]types.ChainMsg, error) {
|
||||||
if len(ts.Blocks()) != 1 {
|
if len(ts.Blocks()) != 1 {
|
||||||
panic("cant deal with multiblock tipsets in this test")
|
panic("cant deal with multiblock tipsets in this test")
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ func (tma *testMpoolApi) MessagesForTipset(ts *types.TipSet) ([]types.ChainMsg,
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tma *testMpoolApi) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
|
func (tma *testMpoolAPI) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
|
||||||
for _, ts := range tma.tipsets {
|
for _, ts := range tma.tipsets {
|
||||||
if types.CidArrsEqual(tsk.Cids(), ts.Cids()) {
|
if types.CidArrsEqual(tsk.Cids(), ts.Cids()) {
|
||||||
return ts, nil
|
return ts, nil
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
var log = logging.Logger("statetree")
|
var log = logging.Logger("statetree")
|
||||||
|
|
||||||
// Stores actors state by their ID.
|
// StateTree stores actors state by their ID.
|
||||||
type StateTree struct {
|
type StateTree struct {
|
||||||
root *hamt.Node
|
root *hamt.Node
|
||||||
Store cbor.IpldStore
|
Store cbor.IpldStore
|
||||||
@ -149,7 +149,7 @@ func (st *StateTree) SetActor(addr address.Address, act *types.Actor) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// `LookupID` gets the ID address of this actor's `addr` stored in the `InitActor`.
|
// LookupID gets the ID address of this actor's `addr` stored in the `InitActor`.
|
||||||
func (st *StateTree) LookupID(addr address.Address) (address.Address, error) {
|
func (st *StateTree) LookupID(addr address.Address) (address.Address, error) {
|
||||||
if addr.Protocol() == address.ID {
|
if addr.Protocol() == address.ID {
|
||||||
return addr, nil
|
return addr, nil
|
||||||
|
@ -326,7 +326,7 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
|||||||
blkmsgs = append(blkmsgs, bm)
|
blkmsgs = append(blkmsgs, bm)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sm.ApplyBlocks(ctx, pstate, blkmsgs, abi.ChainEpoch(blks[0].Height), r, cb)
|
return sm.ApplyBlocks(ctx, pstate, blkmsgs, blks[0].Height, r, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) parentState(ts *types.TipSet) cid.Cid {
|
func (sm *StateManager) parentState(ts *types.TipSet) cid.Cid {
|
||||||
@ -405,8 +405,8 @@ func (sm *StateManager) LoadActorStateRaw(ctx context.Context, a address.Address
|
|||||||
return act, nil
|
return act, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar to `vm.ResolveToKeyAddr` but does not allow `Actor` type of addresses. Uses the `TipSet` `ts`
|
// ResolveToKeyAddr is similar to `vm.ResolveToKeyAddr` but does not allow `Actor` type of addresses.
|
||||||
// to generate the VM state.
|
// Uses the `TipSet` `ts` to generate the VM state.
|
||||||
func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
func (sm *StateManager) ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
||||||
switch addr.Protocol() {
|
switch addr.Protocol() {
|
||||||
case address.BLS, address.SECP256K1:
|
case address.BLS, address.SECP256K1:
|
||||||
|
@ -286,7 +286,7 @@ func GetMinerRecoveries(ctx context.Context, sm *StateManager, ts *types.TipSet,
|
|||||||
return mas.Recoveries, nil
|
return mas.Recoveries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) {
|
func GetStorageDeal(ctx context.Context, sm *StateManager, dealID abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) {
|
||||||
var state market.State
|
var state market.State
|
||||||
if _, err := sm.LoadActorState(ctx, builtin.StorageMarketActorAddr, &state, ts); err != nil {
|
if _, err := sm.LoadActorState(ctx, builtin.StorageMarketActorAddr, &state, ts); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -298,7 +298,7 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dp market.DealProposal
|
var dp market.DealProposal
|
||||||
if err := da.Get(ctx, uint64(dealId), &dp); err != nil {
|
if err := da.Get(ctx, uint64(dealID), &dp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
st, found, err := sa.Get(dealId)
|
st, found, err := sa.Get(dealID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,7 @@ func (cs *ChainStore) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
|
|||||||
return ts, nil
|
return ts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if 'a' is an ancestor of 'b'
|
// IsAncestorOf returns true if 'a' is an ancestor of 'b'
|
||||||
func (cs *ChainStore) IsAncestorOf(a, b *types.TipSet) (bool, error) {
|
func (cs *ChainStore) IsAncestorOf(a, b *types.TipSet) (bool, error) {
|
||||||
if b.Height() <= a.Height() {
|
if b.Height() <= a.Height() {
|
||||||
return false, nil
|
return false, nil
|
||||||
@ -1154,7 +1154,6 @@ func (cr *chainRand) GetRandomness(ctx context.Context, pers crypto.DomainSepara
|
|||||||
func (cs *ChainStore) GetTipSetFromKey(tsk types.TipSetKey) (*types.TipSet, error) {
|
func (cs *ChainStore) GetTipSetFromKey(tsk types.TipSetKey) (*types.TipSet, error) {
|
||||||
if tsk.IsEmpty() {
|
if tsk.IsEmpty() {
|
||||||
return cs.GetHeaviestTipSet(), nil
|
return cs.GetHeaviestTipSet(), nil
|
||||||
} else {
|
|
||||||
return cs.LoadTipSet(tsk)
|
|
||||||
}
|
}
|
||||||
|
return cs.LoadTipSet(tsk)
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,7 @@ func HandleIncomingBlocks(ctx context.Context, bsub *pubsub.Subscription, s *cha
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:golint
|
src := msg.GetFrom()
|
||||||
src := peer.ID(msg.GetFrom())
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Infof("New block over pubsub: %s", blk.Cid())
|
log.Infof("New block over pubsub: %s", blk.Cid())
|
||||||
@ -207,7 +206,7 @@ func (bv *BlockValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sigs.CheckBlockSignature(blk.Header, ctx, key)
|
err = sigs.CheckBlockSignature(ctx, blk.Header, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("block signature verification failed: %s", err)
|
log.Errorf("block signature verification failed: %s", err)
|
||||||
recordFailure("signature_verification_failed")
|
recordFailure("signature_verification_failed")
|
||||||
|
@ -526,7 +526,7 @@ func blockSanityChecks(h *types.BlockHeader) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should match up with 'Semantical Validation' in validation.md in the spec
|
// ValidateBlock should match up with 'Semantical Validation' in validation.md in the spec
|
||||||
func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) error {
|
func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) error {
|
||||||
ctx, span := trace.StartSpan(ctx, "validateBlock")
|
ctx, span := trace.StartSpan(ctx, "validateBlock")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@ -665,7 +665,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
|
|||||||
})
|
})
|
||||||
|
|
||||||
blockSigCheck := async.Err(func() error {
|
blockSigCheck := async.Err(func() error {
|
||||||
if err := sigs.CheckBlockSignature(h, ctx, waddr); err != nil {
|
if err := sigs.CheckBlockSignature(ctx, h, waddr); err != nil {
|
||||||
return xerrors.Errorf("check block signature failed: %w", err)
|
return xerrors.Errorf("check block signature failed: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -74,8 +74,8 @@ type BlockHeader struct {
|
|||||||
validated bool // true if the signature has been validated
|
validated bool // true if the signature has been validated
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
|
func (blk *BlockHeader) ToStorageBlock() (block.Block, error) {
|
||||||
data, err := b.Serialize()
|
data, err := blk.Serialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -89,8 +89,8 @@ func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
|
|||||||
return block.NewBlockWithCid(data, c)
|
return block.NewBlockWithCid(data, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlockHeader) Cid() cid.Cid {
|
func (blk *BlockHeader) Cid() cid.Cid {
|
||||||
sb, err := b.ToStorageBlock()
|
sb, err := blk.ToStorageBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // Not sure i'm entirely comfortable with this one, needs to be checked
|
panic(err) // Not sure i'm entirely comfortable with this one, needs to be checked
|
||||||
}
|
}
|
||||||
|
@ -41,20 +41,16 @@ type Message struct {
|
|||||||
Params []byte
|
Params []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Message) BlockMiner() address.Address {
|
func (m *Message) Caller() address.Address {
|
||||||
panic("implement me")
|
return m.From
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Message) Caller() address.Address {
|
func (m *Message) Receiver() address.Address {
|
||||||
return t.From
|
return m.To
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Message) Receiver() address.Address {
|
func (m *Message) ValueReceived() abi.TokenAmount {
|
||||||
return t.To
|
return m.Value
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Message) ValueReceived() abi.TokenAmount {
|
|
||||||
return t.Value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeMessage(b []byte) (*Message, error) {
|
func DecodeMessage(b []byte) (*Message, error) {
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *SignedMessage) ToStorageBlock() (block.Block, error) {
|
func (sm *SignedMessage) ToStorageBlock() (block.Block, error) {
|
||||||
if m.Signature.Type == crypto.SigTypeBLS {
|
if sm.Signature.Type == crypto.SigTypeBLS {
|
||||||
return m.Message.ToStorageBlock()
|
return sm.Message.ToStorageBlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := m.Serialize()
|
data, err := sm.Serialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -28,12 +28,12 @@ func (m *SignedMessage) ToStorageBlock() (block.Block, error) {
|
|||||||
return block.NewBlockWithCid(data, c)
|
return block.NewBlockWithCid(data, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SignedMessage) Cid() cid.Cid {
|
func (sm *SignedMessage) Cid() cid.Cid {
|
||||||
if m.Signature.Type == crypto.SigTypeBLS {
|
if sm.Signature.Type == crypto.SigTypeBLS {
|
||||||
return m.Message.Cid()
|
return sm.Message.Cid()
|
||||||
}
|
}
|
||||||
|
|
||||||
sb, err := m.ToStorageBlock()
|
sb, err := sm.ToStorageBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@ type TipSet struct {
|
|||||||
height abi.ChainEpoch
|
height abi.ChainEpoch
|
||||||
}
|
}
|
||||||
|
|
||||||
// why didnt i just export the fields? Because the struct has methods with the
|
|
||||||
// same names already
|
|
||||||
type ExpTipSet struct {
|
type ExpTipSet struct {
|
||||||
Cids []cid.Cid
|
Cids []cid.Cid
|
||||||
Blocks []*BlockHeader
|
Blocks []*BlockHeader
|
||||||
@ -32,6 +30,8 @@ type ExpTipSet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TipSet) MarshalJSON() ([]byte, error) {
|
func (ts *TipSet) MarshalJSON() ([]byte, error) {
|
||||||
|
// why didnt i just export the fields? Because the struct has methods with the
|
||||||
|
// same names already
|
||||||
return json.Marshal(ExpTipSet{
|
return json.Marshal(ExpTipSet{
|
||||||
Cids: ts.cids,
|
Cids: ts.cids,
|
||||||
Blocks: ts.blks,
|
Blocks: ts.blks,
|
||||||
|
@ -61,9 +61,9 @@ func TestTipSetKey(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("JSON", func(t *testing.T) {
|
t.Run("JSON", func(t *testing.T) {
|
||||||
k0 := NewTipSetKey()
|
k0 := NewTipSetKey()
|
||||||
verifyJson(t, "[]", k0)
|
verifyJSON(t, "[]", k0)
|
||||||
k3 := NewTipSetKey(c1, c2, c3)
|
k3 := NewTipSetKey(c1, c2, c3)
|
||||||
verifyJson(t, `[`+
|
verifyJSON(t, `[`+
|
||||||
`{"/":"bafy2bzacecesrkxghscnq7vatble2hqdvwat6ed23vdu4vvo3uuggsoaya7ki"},`+
|
`{"/":"bafy2bzacecesrkxghscnq7vatble2hqdvwat6ed23vdu4vvo3uuggsoaya7ki"},`+
|
||||||
`{"/":"bafy2bzacebxfyh2fzoxrt6kcgc5dkaodpcstgwxxdizrww225vrhsizsfcg4g"},`+
|
`{"/":"bafy2bzacebxfyh2fzoxrt6kcgc5dkaodpcstgwxxdizrww225vrhsizsfcg4g"},`+
|
||||||
`{"/":"bafy2bzacedwviarjtjraqakob5pslltmuo5n3xev3nt5zylezofkbbv5jclyu"}`+
|
`{"/":"bafy2bzacedwviarjtjraqakob5pslltmuo5n3xev3nt5zylezofkbbv5jclyu"}`+
|
||||||
@ -71,7 +71,7 @@ func TestTipSetKey(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyJson(t *testing.T, expected string, k TipSetKey) {
|
func verifyJSON(t *testing.T, expected string, k TipSetKey) {
|
||||||
bytes, err := json.Marshal(k)
|
bytes, err := json.Marshal(k)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, expected, string(bytes))
|
assert.Equal(t, expected, string(bytes))
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type invoker struct {
|
type Invoker struct {
|
||||||
builtInCode map[cid.Cid]nativeCode
|
builtInCode map[cid.Cid]nativeCode
|
||||||
builtInState map[cid.Cid]reflect.Type
|
builtInState map[cid.Cid]reflect.Type
|
||||||
}
|
}
|
||||||
@ -40,8 +40,8 @@ type invoker struct {
|
|||||||
type invokeFunc func(rt runtime.Runtime, params []byte) ([]byte, aerrors.ActorError)
|
type invokeFunc func(rt runtime.Runtime, params []byte) ([]byte, aerrors.ActorError)
|
||||||
type nativeCode []invokeFunc
|
type nativeCode []invokeFunc
|
||||||
|
|
||||||
func NewInvoker() *invoker {
|
func NewInvoker() *Invoker {
|
||||||
inv := &invoker{
|
inv := &Invoker{
|
||||||
builtInCode: make(map[cid.Cid]nativeCode),
|
builtInCode: make(map[cid.Cid]nativeCode),
|
||||||
builtInState: make(map[cid.Cid]reflect.Type),
|
builtInState: make(map[cid.Cid]reflect.Type),
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ func NewInvoker() *invoker {
|
|||||||
return inv
|
return inv
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inv *invoker) Invoke(codeCid cid.Cid, rt runtime.Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) {
|
func (inv *Invoker) Invoke(codeCid cid.Cid, rt runtime.Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) {
|
||||||
|
|
||||||
code, ok := inv.builtInCode[codeCid]
|
code, ok := inv.builtInCode[codeCid]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -76,7 +76,7 @@ func (inv *invoker) Invoke(codeCid cid.Cid, rt runtime.Runtime, method abi.Metho
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inv *invoker) Register(c cid.Cid, instance Invokee, state interface{}) {
|
func (inv *Invoker) Register(c cid.Cid, instance Invokee, state interface{}) {
|
||||||
code, err := inv.transform(instance)
|
code, err := inv.transform(instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(xerrors.Errorf("%s: %w", string(c.Hash()), err))
|
panic(xerrors.Errorf("%s: %w", string(c.Hash()), err))
|
||||||
@ -89,9 +89,7 @@ type Invokee interface {
|
|||||||
Exports() []interface{}
|
Exports() []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tAError = reflect.TypeOf((*aerrors.ActorError)(nil)).Elem()
|
func (*Invoker) transform(instance Invokee) (nativeCode, error) {
|
||||||
|
|
||||||
func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|
||||||
itype := reflect.TypeOf(instance)
|
itype := reflect.TypeOf(instance)
|
||||||
exports := instance.Exports()
|
exports := instance.Exports()
|
||||||
for i, m := range exports {
|
for i, m := range exports {
|
||||||
|
@ -76,7 +76,7 @@ func (basicContract) InvokeSomething10(rt runtime.Runtime, params *basicParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvokerBasic(t *testing.T) {
|
func TestInvokerBasic(t *testing.T) {
|
||||||
inv := invoker{}
|
inv := Invoker{}
|
||||||
code, err := inv.transform(basicContract{})
|
code, err := inv.transform(basicContract{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package vm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
@ -27,7 +28,7 @@ func init() {
|
|||||||
|
|
||||||
var EmptyObjectCid cid.Cid
|
var EmptyObjectCid cid.Cid
|
||||||
|
|
||||||
// Creates account actors from only BLS/SECP256K1 addresses.
|
// TryCreateAccountActor creates account actors from only BLS/SECP256K1 addresses.
|
||||||
func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) {
|
func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) {
|
||||||
addrID, err := rt.state.RegisterNewAddress(addr)
|
addrID, err := rt.state.RegisterNewAddress(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -106,8 +106,8 @@ type notFoundErr interface {
|
|||||||
IsNotFound() bool
|
IsNotFound() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool {
|
func (rt *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool {
|
||||||
if err := rs.cst.Get(context.TODO(), c, o); err != nil {
|
if err := rt.cst.Get(context.TODO(), c, o); err != nil {
|
||||||
var nfe notFoundErr
|
var nfe notFoundErr
|
||||||
if xerrors.As(err, &nfe) && nfe.IsNotFound() {
|
if xerrors.As(err, &nfe) && nfe.IsNotFound() {
|
||||||
if xerrors.As(err, new(cbor.SerializationError)) {
|
if xerrors.As(err, new(cbor.SerializationError)) {
|
||||||
@ -121,8 +121,8 @@ func (rs *Runtime) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Put(x vmr.CBORMarshaler) cid.Cid {
|
func (rt *Runtime) Put(x vmr.CBORMarshaler) cid.Cid {
|
||||||
c, err := rs.cst.Put(context.TODO(), x)
|
c, err := rt.cst.Put(context.TODO(), x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if xerrors.As(err, new(cbor.SerializationError)) {
|
if xerrors.As(err, new(cbor.SerializationError)) {
|
||||||
panic(aerrors.Newf(exitcode.ErrSerialization, "failed to marshal cbor object %s", err))
|
panic(aerrors.Newf(exitcode.ErrSerialization, "failed to marshal cbor object %s", err))
|
||||||
@ -134,7 +134,7 @@ func (rs *Runtime) Put(x vmr.CBORMarshaler) cid.Cid {
|
|||||||
|
|
||||||
var _ vmr.Runtime = (*Runtime)(nil)
|
var _ vmr.Runtime = (*Runtime)(nil)
|
||||||
|
|
||||||
func (rs *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.ActorError) {
|
func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.ActorError) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
if ar, ok := r.(aerrors.ActorError); ok {
|
if ar, ok := r.(aerrors.ActorError); ok {
|
||||||
@ -149,8 +149,8 @@ func (rs *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act
|
|||||||
|
|
||||||
ret := f()
|
ret := f()
|
||||||
|
|
||||||
if !rs.callerValidated {
|
if !rt.callerValidated {
|
||||||
rs.Abortf(exitcode.SysErrorIllegalActor, "Caller MUST be validated during method execution")
|
rt.Abortf(exitcode.SysErrorIllegalActor, "Caller MUST be validated during method execution")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ret := ret.(type) {
|
switch ret := ret.(type) {
|
||||||
@ -171,25 +171,25 @@ func (rs *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Message() vmr.Message {
|
func (rt *Runtime) Message() vmr.Message {
|
||||||
return rs.vmsg
|
return rt.vmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) ValidateImmediateCallerAcceptAny() {
|
func (rt *Runtime) ValidateImmediateCallerAcceptAny() {
|
||||||
rs.abortIfAlreadyValidated()
|
rt.abortIfAlreadyValidated()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) CurrentBalance() abi.TokenAmount {
|
func (rt *Runtime) CurrentBalance() abi.TokenAmount {
|
||||||
b, err := rs.GetBalance(rs.Message().Receiver())
|
b, err := rt.GetBalance(rt.Message().Receiver())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rs.Abortf(err.RetCode(), "get current balance: %v", err)
|
rt.Abortf(err.RetCode(), "get current balance: %v", err)
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) GetActorCodeCID(addr address.Address) (ret cid.Cid, ok bool) {
|
func (rt *Runtime) GetActorCodeCID(addr address.Address) (ret cid.Cid, ok bool) {
|
||||||
act, err := rs.state.GetActor(addr)
|
act, err := rt.state.GetActor(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if xerrors.Is(err, types.ErrActorNotFound) {
|
if xerrors.Is(err, types.ErrActorNotFound) {
|
||||||
return cid.Undef, false
|
return cid.Undef, false
|
||||||
@ -209,8 +209,8 @@ func (rt *Runtime) GetRandomness(personalization crypto.DomainSeparationTag, ran
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Store() vmr.Store {
|
func (rt *Runtime) Store() vmr.Store {
|
||||||
return rs
|
return rt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) NewActorAddress() address.Address {
|
func (rt *Runtime) NewActorAddress() address.Address {
|
||||||
@ -235,12 +235,12 @@ func (rt *Runtime) NewActorAddress() address.Address {
|
|||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) CreateActor(codeId cid.Cid, address address.Address) {
|
func (rt *Runtime) CreateActor(codeID cid.Cid, address address.Address) {
|
||||||
if !builtin.IsBuiltinActor(codeId) {
|
if !builtin.IsBuiltinActor(codeID) {
|
||||||
rt.Abortf(exitcode.SysErrorIllegalArgument, "Can only create built-in actors.")
|
rt.Abortf(exitcode.SysErrorIllegalArgument, "Can only create built-in actors.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if builtin.IsSingletonActor(codeId) {
|
if builtin.IsSingletonActor(codeID) {
|
||||||
rt.Abortf(exitcode.SysErrorIllegalArgument, "Can only have one instance of singleton actors.")
|
rt.Abortf(exitcode.SysErrorIllegalArgument, "Can only have one instance of singleton actors.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ func (rt *Runtime) CreateActor(codeId cid.Cid, address address.Address) {
|
|||||||
rt.ChargeGas(rt.Pricelist().OnCreateActor())
|
rt.ChargeGas(rt.Pricelist().OnCreateActor())
|
||||||
|
|
||||||
err = rt.state.SetActor(address, &types.Actor{
|
err = rt.state.SetActor(address, &types.Actor{
|
||||||
Code: codeId,
|
Code: codeID,
|
||||||
Head: EmptyObjectCid,
|
Head: EmptyObjectCid,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
Balance: big.Zero(),
|
Balance: big.Zero(),
|
||||||
@ -282,12 +282,12 @@ func (rt *Runtime) DeleteActor(addr address.Address) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Syscalls() vmr.Syscalls {
|
func (rt *Runtime) Syscalls() vmr.Syscalls {
|
||||||
// TODO: Make sure this is wrapped in something that charges gas for each of the calls
|
// TODO: Make sure this is wrapped in something that charges gas for each of the calls
|
||||||
return rs.sys
|
return rt.sys
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) StartSpan(name string) vmr.TraceSpan {
|
func (rt *Runtime) StartSpan(name string) vmr.TraceSpan {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,12 +307,12 @@ func (rt *Runtime) Context() context.Context {
|
|||||||
return rt.ctx
|
return rt.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Abortf(code exitcode.ExitCode, msg string, args ...interface{}) {
|
func (rt *Runtime) Abortf(code exitcode.ExitCode, msg string, args ...interface{}) {
|
||||||
log.Error("Abortf: ", fmt.Sprintf(msg, args...))
|
log.Error("Abortf: ", fmt.Sprintf(msg, args...))
|
||||||
panic(aerrors.NewfSkip(2, code, msg, args...))
|
panic(aerrors.NewfSkip(2, code, msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) AbortStateMsg(msg string) {
|
func (rt *Runtime) AbortStateMsg(msg string) {
|
||||||
panic(aerrors.NewfSkip(3, 101, msg))
|
panic(aerrors.NewfSkip(3, 101, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,8 +330,8 @@ func (rt *Runtime) ValidateImmediateCallerType(ts ...cid.Cid) {
|
|||||||
rt.Abortf(exitcode.SysErrForbidden, "caller cid type %q was not one of %v", callerCid, ts)
|
rt.Abortf(exitcode.SysErrForbidden, "caller cid type %q was not one of %v", callerCid, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) CurrEpoch() abi.ChainEpoch {
|
func (rt *Runtime) CurrEpoch() abi.ChainEpoch {
|
||||||
return rs.height
|
return rt.height
|
||||||
}
|
}
|
||||||
|
|
||||||
type dumbWrapperType struct {
|
type dumbWrapperType struct {
|
||||||
@ -342,20 +342,20 @@ func (dwt *dumbWrapperType) Into(um vmr.CBORUnmarshaler) error {
|
|||||||
return um.UnmarshalCBOR(bytes.NewReader(dwt.val))
|
return um.UnmarshalCBOR(bytes.NewReader(dwt.val))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) Send(to address.Address, method abi.MethodNum, m vmr.CBORMarshaler, value abi.TokenAmount) (vmr.SendReturn, exitcode.ExitCode) {
|
func (rt *Runtime) Send(to address.Address, method abi.MethodNum, m vmr.CBORMarshaler, value abi.TokenAmount) (vmr.SendReturn, exitcode.ExitCode) {
|
||||||
if !rs.allowInternal {
|
if !rt.allowInternal {
|
||||||
rs.Abortf(exitcode.SysErrorIllegalActor, "runtime.Send() is currently disallowed")
|
rt.Abortf(exitcode.SysErrorIllegalActor, "runtime.Send() is currently disallowed")
|
||||||
}
|
}
|
||||||
var params []byte
|
var params []byte
|
||||||
if m != nil {
|
if m != nil {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := m.MarshalCBOR(buf); err != nil {
|
if err := m.MarshalCBOR(buf); err != nil {
|
||||||
rs.Abortf(exitcode.SysErrInvalidParameters, "failed to marshal input parameters: %s", err)
|
rt.Abortf(exitcode.SysErrInvalidParameters, "failed to marshal input parameters: %s", err)
|
||||||
}
|
}
|
||||||
params = buf.Bytes()
|
params = buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := rs.internalSend(rs.Message().Receiver(), to, method, value, params)
|
ret, err := rt.internalSend(rt.Message().Receiver(), to, method, value, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.IsFatal() {
|
if err.IsFatal() {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -422,48 +422,48 @@ func (rt *Runtime) internalSend(from, to address.Address, method abi.MethodNum,
|
|||||||
return ret, errSend
|
return ret, errSend
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *Runtime) State() vmr.StateHandle {
|
func (rt *Runtime) State() vmr.StateHandle {
|
||||||
return &shimStateHandle{rs: rs}
|
return &shimStateHandle{rt: rt}
|
||||||
}
|
}
|
||||||
|
|
||||||
type shimStateHandle struct {
|
type shimStateHandle struct {
|
||||||
rs *Runtime
|
rt *Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) {
|
func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) {
|
||||||
c := ssh.rs.Put(obj)
|
c := ssh.rt.Put(obj)
|
||||||
// TODO: handle error below
|
// TODO: handle error below
|
||||||
ssh.rs.stateCommit(EmptyObjectCid, c)
|
ssh.rt.stateCommit(EmptyObjectCid, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshaler) {
|
func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshaler) {
|
||||||
act, err := ssh.rs.state.GetActor(ssh.rs.Message().Receiver())
|
act, err := ssh.rt.state.GetActor(ssh.rt.Message().Receiver())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ssh.rs.Abortf(exitcode.SysErrorIllegalArgument, "failed to get actor for Readonly state: %s", err)
|
ssh.rt.Abortf(exitcode.SysErrorIllegalArgument, "failed to get actor for Readonly state: %s", err)
|
||||||
}
|
}
|
||||||
ssh.rs.Get(act.Head, obj)
|
ssh.rt.Get(act.Head, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func() interface{}) interface{} {
|
func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func() interface{}) interface{} {
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
ssh.rs.Abortf(exitcode.SysErrorIllegalActor, "Must not pass nil to Transaction()")
|
ssh.rt.Abortf(exitcode.SysErrorIllegalActor, "Must not pass nil to Transaction()")
|
||||||
}
|
}
|
||||||
|
|
||||||
act, err := ssh.rs.state.GetActor(ssh.rs.Message().Receiver())
|
act, err := ssh.rt.state.GetActor(ssh.rt.Message().Receiver())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ssh.rs.Abortf(exitcode.SysErrorIllegalActor, "failed to get actor for Transaction: %s", err)
|
ssh.rt.Abortf(exitcode.SysErrorIllegalActor, "failed to get actor for Transaction: %s", err)
|
||||||
}
|
}
|
||||||
baseState := act.Head
|
baseState := act.Head
|
||||||
ssh.rs.Get(baseState, obj)
|
ssh.rt.Get(baseState, obj)
|
||||||
|
|
||||||
ssh.rs.allowInternal = false
|
ssh.rt.allowInternal = false
|
||||||
out := f()
|
out := f()
|
||||||
ssh.rs.allowInternal = true
|
ssh.rt.allowInternal = true
|
||||||
|
|
||||||
c := ssh.rs.Put(obj)
|
c := ssh.rt.Put(obj)
|
||||||
|
|
||||||
// TODO: handle error below
|
// TODO: handle error below
|
||||||
ssh.rs.stateCommit(baseState, c)
|
ssh.rt.stateCommit(baseState, c)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sigs.CheckBlockSignature(blk, ss.ctx, waddr); err != nil {
|
if err := sigs.CheckBlockSignature(ss.ctx, blk, waddr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,20 +202,6 @@ func (ss *syscallShim) VerifyPoSt(proof abi.WindowPoStVerifyInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cidToCommD(c cid.Cid) [32]byte {
|
|
||||||
b := c.Bytes()
|
|
||||||
var out [32]byte
|
|
||||||
copy(out[:], b[len(b)-32:])
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func cidToCommR(c cid.Cid) [32]byte {
|
|
||||||
b := c.Bytes()
|
|
||||||
var out [32]byte
|
|
||||||
copy(out[:], b[len(b)-32:])
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss *syscallShim) VerifySeal(info abi.SealVerifyInfo) error {
|
func (ss *syscallShim) VerifySeal(info abi.SealVerifyInfo) error {
|
||||||
//_, span := trace.StartSpan(ctx, "ValidatePoRep")
|
//_, span := trace.StartSpan(ctx, "ValidatePoRep")
|
||||||
//defer span.End()
|
//defer span.End()
|
||||||
|
@ -131,7 +131,7 @@ type VM struct {
|
|||||||
cst *cbor.BasicIpldStore
|
cst *cbor.BasicIpldStore
|
||||||
buf *bufbstore.BufferedBS
|
buf *bufbstore.BufferedBS
|
||||||
blockHeight abi.ChainEpoch
|
blockHeight abi.ChainEpoch
|
||||||
inv *invoker
|
inv *Invoker
|
||||||
rand Rand
|
rand Rand
|
||||||
|
|
||||||
Syscalls runtime.Syscalls
|
Syscalls runtime.Syscalls
|
||||||
@ -454,7 +454,7 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) {
|
|||||||
return root, nil
|
return root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// vm.MutateState(idAddr, func(cst cbor.IpldStore, st *ActorStateType) error {...})
|
// MutateState usage: MutateState(ctx, idAddr, func(cst cbor.IpldStore, st *ActorStateType) error {...})
|
||||||
func (vm *VM) MutateState(ctx context.Context, addr address.Address, fn interface{}) error {
|
func (vm *VM) MutateState(ctx context.Context, addr address.Address, fn interface{}) error {
|
||||||
act, err := vm.cstate.GetActor(addr)
|
act, err := vm.cstate.GetActor(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -591,7 +591,7 @@ func (vm *VM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VM) SetInvoker(i *invoker) {
|
func (vm *VM) SetInvoker(i *Invoker) {
|
||||||
vm.inv = i
|
vm.inv = i
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,17 +607,17 @@ func (vm *VM) transfer(from, to address.Address, amt types.BigInt) aerrors.Actor
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fromId, err := vm.cstate.LookupID(from)
|
fromID, err := vm.cstate.LookupID(from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.Fatalf("transfer failed when resolving sender address: %s", err)
|
return aerrors.Fatalf("transfer failed when resolving sender address: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
toId, err := vm.cstate.LookupID(to)
|
toID, err := vm.cstate.LookupID(to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.Fatalf("transfer failed when resolving receiver address: %s", err)
|
return aerrors.Fatalf("transfer failed when resolving receiver address: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fromId == toId {
|
if fromID == toID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,12 +625,12 @@ func (vm *VM) transfer(from, to address.Address, amt types.BigInt) aerrors.Actor
|
|||||||
return aerrors.Newf(exitcode.SysErrForbidden, "attempted to transfer negative value: %s", amt)
|
return aerrors.Newf(exitcode.SysErrForbidden, "attempted to transfer negative value: %s", amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := vm.cstate.GetActor(fromId)
|
f, err := vm.cstate.GetActor(fromID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.Fatalf("transfer failed when retrieving sender actor: %s", err)
|
return aerrors.Fatalf("transfer failed when retrieving sender actor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := vm.cstate.GetActor(toId)
|
t, err := vm.cstate.GetActor(toID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return aerrors.Fatalf("transfer failed when retrieving receiver actor: %s", err)
|
return aerrors.Fatalf("transfer failed when retrieving receiver actor: %s", err)
|
||||||
}
|
}
|
||||||
@ -640,11 +640,11 @@ func (vm *VM) transfer(from, to address.Address, amt types.BigInt) aerrors.Actor
|
|||||||
}
|
}
|
||||||
depositFunds(t, amt)
|
depositFunds(t, amt)
|
||||||
|
|
||||||
if err := vm.cstate.SetActor(fromId, f); err != nil {
|
if err := vm.cstate.SetActor(fromID, f); err != nil {
|
||||||
return aerrors.Fatalf("transfer failed when setting receiver actor: %s", err)
|
return aerrors.Fatalf("transfer failed when setting receiver actor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := vm.cstate.SetActor(toId, t); err != nil {
|
if err := vm.cstate.SetActor(toID, t); err != nil {
|
||||||
return aerrors.Fatalf("transfer failed when setting sender actor: %s", err)
|
return aerrors.Fatalf("transfer failed when setting sender actor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func subBlocks(ctx context.Context, api aapi.FullNode, st *storage) {
|
|||||||
bh.Cid(): bh,
|
bh.Cid(): bh,
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//log.Errorf("%+v", err)
|
log.Errorf("%+v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,13 @@ var dotCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
minH, err := strconv.ParseInt(cctx.Args().Get(0), 10, 32)
|
minH, err := strconv.ParseInt(cctx.Args().Get(0), 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
tosee, err := strconv.ParseInt(cctx.Args().Get(1), 10, 32)
|
tosee, err := strconv.ParseInt(cctx.Args().Get(1), 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
maxH := minH + tosee
|
maxH := minH + tosee
|
||||||
|
|
||||||
res, err := st.db.Query(`select block, parent, b.miner, b.height, p.height from block_parents
|
res, err := st.db.Query(`select block, parent, b.miner, b.height, p.height from block_parents
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
var log = logging.Logger("chainwatch")
|
var log = logging.Logger("chainwatch")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logging.SetLogLevel("*", "INFO")
|
_ = logging.SetLogLevel("*", "INFO")
|
||||||
|
|
||||||
log.Info("Starting chainwatch")
|
log.Info("Starting chainwatch")
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(bh.Parents) == 0 { // genesis case
|
if len(bh.Parents) == 0 { // genesis case
|
||||||
ts, err := types.NewTipSet([]*types.BlockHeader{bh})
|
ts, _ := types.NewTipSet([]*types.BlockHeader{bh})
|
||||||
aadrs, err := api.StateListActors(ctx, ts.Key())
|
aadrs, err := api.StateListActors(ctx, ts.Key())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -215,14 +215,14 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
|
|||||||
owner, err := address.NewFromString(r.FormValue("address"))
|
owner, err := address.NewFromString(r.FormValue("address"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte(err.Error()))
|
_, _ = w.Write([]byte(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if owner.Protocol() != address.BLS {
|
if owner.Protocol() != address.BLS {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte("Miner address must use BLS. A BLS address starts with the prefix 't3'."))
|
_, _ = w.Write([]byte("Miner address must use BLS. A BLS address starts with the prefix 't3'."))
|
||||||
w.Write([]byte("Please create a BLS address by running \"lotus wallet new bls\" while connected to a Lotus node."))
|
_, _ = w.Write([]byte("Please create a BLS address by running \"lotus wallet new bls\" while connected to a Lotus node."))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MapArr transforms map into slice of map values
|
||||||
func MapArr(in interface{}) interface{} {
|
func MapArr(in interface{}) interface{} {
|
||||||
rin := reflect.ValueOf(in)
|
rin := reflect.ValueOf(in)
|
||||||
rout := reflect.MakeSlice(reflect.SliceOf(rin.Type().Elem()), rin.Len(), rin.Len())
|
rout := reflect.MakeSlice(reflect.SliceOf(rin.Type().Elem()), rin.Len(), rin.Len())
|
||||||
@ -19,6 +20,7 @@ func MapArr(in interface{}) interface{} {
|
|||||||
return rout.Interface()
|
return rout.Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KMapArr transforms map into slice of map keys
|
||||||
func KMapArr(in interface{}) interface{} {
|
func KMapArr(in interface{}) interface{} {
|
||||||
rin := reflect.ValueOf(in)
|
rin := reflect.ValueOf(in)
|
||||||
rout := reflect.MakeSlice(reflect.SliceOf(rin.Type().Key()), rin.Len(), rin.Len())
|
rout := reflect.MakeSlice(reflect.SliceOf(rin.Type().Key()), rin.Len(), rin.Len())
|
||||||
@ -33,7 +35,8 @@ func KMapArr(in interface{}) interface{} {
|
|||||||
return rout.Interface()
|
return rout.Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
// map[k]v => []func() (k, v)
|
// KMapArr transforms map into slice of functions returning (key, val) pairs.
|
||||||
|
// map[A]B => []func()(A, B)
|
||||||
func KVMapArr(in interface{}) interface{} {
|
func KVMapArr(in interface{}) interface{} {
|
||||||
rin := reflect.ValueOf(in)
|
rin := reflect.ValueOf(in)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Sigs package allows for signing, verifying signatures and key generation
|
// Package sigs allows for signing, verifying signatures and key generation
|
||||||
// using key types selected by package user.
|
// using key types selected by package user.
|
||||||
//
|
//
|
||||||
// For support of secp256k1 import:
|
// For support of secp256k1 import:
|
||||||
|
@ -68,7 +68,7 @@ func ToPublic(sigType crypto.SigType, pk []byte) ([]byte, error) {
|
|||||||
return sv.ToPublic(pk)
|
return sv.ToPublic(pk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckBlockSignature(blk *types.BlockHeader, ctx context.Context, worker address.Address) error {
|
func CheckBlockSignature(ctx context.Context, blk *types.BlockHeader, worker address.Address) error {
|
||||||
_, span := trace.StartSpan(ctx, "checkBlockSignature")
|
_, span := trace.StartSpan(ctx, "checkBlockSignature")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ type SigShim interface {
|
|||||||
|
|
||||||
var sigs map[crypto.SigType]SigShim
|
var sigs map[crypto.SigType]SigShim
|
||||||
|
|
||||||
// RegisterSig should be only used during init
|
// RegisterSignature should be only used during init
|
||||||
func RegisterSignature(typ crypto.SigType, vs SigShim) {
|
func RegisterSignature(typ crypto.SigType, vs SigShim) {
|
||||||
if sigs == nil {
|
if sigs == nil {
|
||||||
sigs = make(map[crypto.SigType]SigShim)
|
sigs = make(map[crypto.SigType]SigShim)
|
||||||
|
@ -32,7 +32,7 @@ type api struct {
|
|||||||
type nodeInfo struct {
|
type nodeInfo struct {
|
||||||
Repo string
|
Repo string
|
||||||
ID int32
|
ID int32
|
||||||
ApiPort int32
|
APIPort int32
|
||||||
State NodeState
|
State NodeState
|
||||||
|
|
||||||
FullNode string // only for storage nodes
|
FullNode string // only for storage nodes
|
||||||
|
@ -37,7 +37,7 @@ var onCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
node := nodeById(client.Nodes(), int(nd))
|
node := nodeByID(client.Nodes(), int(nd))
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
if !node.Storage {
|
if !node.Storage {
|
||||||
cmd = exec.Command("./lotus", cctx.Args().Slice()[1:]...)
|
cmd = exec.Command("./lotus", cctx.Args().Slice()[1:]...)
|
||||||
@ -75,7 +75,7 @@ var shCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
node := nodeById(client.Nodes(), int(nd))
|
node := nodeByID(client.Nodes(), int(nd))
|
||||||
shcmd := exec.Command("/bin/bash")
|
shcmd := exec.Command("/bin/bash")
|
||||||
if !node.Storage {
|
if !node.Storage {
|
||||||
shcmd.Env = []string{
|
shcmd.Env = []string{
|
||||||
@ -102,7 +102,7 @@ var shCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func nodeById(nodes []nodeInfo, i int) nodeInfo {
|
func nodeByID(nodes []nodeInfo, i int) nodeInfo {
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
if n.ID == int32(i) {
|
if n.ID == int32(i) {
|
||||||
return n
|
return n
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -12,6 +11,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -122,7 +123,7 @@ func (api *api) Spawn() (nodeInfo, error) {
|
|||||||
info := nodeInfo{
|
info := nodeInfo{
|
||||||
Repo: dir,
|
Repo: dir,
|
||||||
ID: id,
|
ID: id,
|
||||||
ApiPort: 2500 + id,
|
APIPort: 2500 + id,
|
||||||
State: NodeRunning,
|
State: NodeRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +199,7 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) {
|
|||||||
info := nodeInfo{
|
info := nodeInfo{
|
||||||
Repo: dir,
|
Repo: dir,
|
||||||
ID: id,
|
ID: id,
|
||||||
ApiPort: 2500 + id,
|
APIPort: 2500 + id,
|
||||||
State: NodeRunning,
|
State: NodeRunning,
|
||||||
|
|
||||||
FullNode: fullNodeRepo,
|
FullNode: fullNodeRepo,
|
||||||
|
@ -682,7 +682,7 @@ func (a *StateAPI) MsigGetAvailableBalance(ctx context.Context, addr address.Add
|
|||||||
return act.Balance, nil
|
return act.Balance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
minBalance := types.BigDiv(types.BigInt(st.InitialBalance), types.NewInt(uint64(st.UnlockDuration)))
|
minBalance := types.BigDiv(st.InitialBalance, types.NewInt(uint64(st.UnlockDuration)))
|
||||||
minBalance = types.BigMul(minBalance, types.NewInt(uint64(offset)))
|
minBalance = types.BigMul(minBalance, types.NewInt(uint64(offset)))
|
||||||
return types.BigSub(act.Balance, minBalance), nil
|
return types.BigSub(act.Balance, minBalance), nil
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ type StorageMinerAPI struct {
|
|||||||
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
|
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
|
||||||
if !auth.HasPerm(r.Context(), nil, apistruct.PermAdmin) {
|
if !auth.HasPerm(r.Context(), nil, apistruct.PermAdmin) {
|
||||||
w.WriteHeader(401)
|
w.WriteHeader(401)
|
||||||
json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
|
_ = json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ func (sm *StorageMinerAPI) MarketImportDealData(ctx context.Context, propCid cid
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to open file: %w", err)
|
return xerrors.Errorf("failed to open file: %w", err)
|
||||||
}
|
}
|
||||||
defer fi.Close()
|
defer fi.Close() //nolint:errcheck
|
||||||
|
|
||||||
return sm.StorageProvider.ImportDataForDeal(ctx, propCid, fi)
|
return sm.StorageProvider.ImportDataForDeal(ctx, propCid, fi)
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ func (sm *StorageMinerAPI) DealsImportData(ctx context.Context, deal cid.Cid, fn
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to open given file: %w", err)
|
return xerrors.Errorf("failed to open given file: %w", err)
|
||||||
}
|
}
|
||||||
defer fi.Close()
|
defer fi.Close() //nolint:errcheck
|
||||||
|
|
||||||
return sm.StorageProvider.ImportDataForDeal(ctx, deal, fi)
|
return sm.StorageProvider.ImportDataForDeal(ctx, deal, fi)
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,7 @@ var ErrRepoExists = xerrors.New("repo exists")
|
|||||||
|
|
||||||
// FsRepo is struct for repo, use NewFS to create
|
// FsRepo is struct for repo, use NewFS to create
|
||||||
type FsRepo struct {
|
type FsRepo struct {
|
||||||
path string
|
path string
|
||||||
repoType RepoType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Repo = &FsRepo{}
|
var _ Repo = &FsRepo{}
|
||||||
|
@ -38,8 +38,7 @@ func (pl *PointList) Points() []models.Point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type InfluxWriteQueue struct {
|
type InfluxWriteQueue struct {
|
||||||
influx client.Client
|
ch chan client.BatchPoints
|
||||||
ch chan client.BatchPoints
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInfluxWriteQueue(ctx context.Context, influx client.Client) *InfluxWriteQueue {
|
func NewInfluxWriteQueue(ctx context.Context, influx client.Client) *InfluxWriteQueue {
|
||||||
|
Loading…
Reference in New Issue
Block a user