use new journal from chain/store pkg.
This commit is contained in:
parent
bef7d64e66
commit
4bcf01938c
@ -54,6 +54,11 @@ var blockValidationCacheKeyPrefix = dstore.NewKey("blockValidation")
|
|||||||
// ReorgNotifee represents a callback that gets called upon reorgs.
|
// ReorgNotifee represents a callback that gets called upon reorgs.
|
||||||
type ReorgNotifee func(rev, app []*types.TipSet) error
|
type ReorgNotifee func(rev, app []*types.TipSet) error
|
||||||
|
|
||||||
|
// Journal event types.
|
||||||
|
const (
|
||||||
|
evtTypeHeadChange = iota
|
||||||
|
)
|
||||||
|
|
||||||
// ChainStore is the main point of access to chain data.
|
// ChainStore is the main point of access to chain data.
|
||||||
//
|
//
|
||||||
// Raw chain data is stored in the Blockstore, with relevant markers (genesis,
|
// Raw chain data is stored in the Blockstore, with relevant markers (genesis,
|
||||||
@ -85,10 +90,12 @@ type ChainStore struct {
|
|||||||
tsCache *lru.ARCCache
|
tsCache *lru.ARCCache
|
||||||
|
|
||||||
vmcalls runtime.Syscalls
|
vmcalls runtime.Syscalls
|
||||||
journal journal.Journal
|
|
||||||
|
journal journal.Journal
|
||||||
|
evtTypes [1]journal.EventType
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChainStore(bs bstore.Blockstore, ds dstore.Batching, vmcalls runtime.Syscalls, journal journal.Journal) *ChainStore {
|
func NewChainStore(bs bstore.Blockstore, ds dstore.Batching, vmcalls runtime.Syscalls, jrnl journal.Journal) *ChainStore {
|
||||||
c, _ := lru.NewARC(2048)
|
c, _ := lru.NewARC(2048)
|
||||||
tsc, _ := lru.NewARC(4096)
|
tsc, _ := lru.NewARC(4096)
|
||||||
cs := &ChainStore{
|
cs := &ChainStore{
|
||||||
@ -99,7 +106,11 @@ func NewChainStore(bs bstore.Blockstore, ds dstore.Batching, vmcalls runtime.Sys
|
|||||||
mmCache: c,
|
mmCache: c,
|
||||||
tsCache: tsc,
|
tsCache: tsc,
|
||||||
vmcalls: vmcalls,
|
vmcalls: vmcalls,
|
||||||
journal: journal,
|
journal: jrnl,
|
||||||
|
}
|
||||||
|
|
||||||
|
cs.evtTypes = [1]journal.EventType{
|
||||||
|
evtTypeHeadChange: jrnl.RegisterEventType("sync", "head_change"),
|
||||||
}
|
}
|
||||||
|
|
||||||
ci := NewChainIndex(cs.LoadTipSet)
|
ci := NewChainIndex(cs.LoadTipSet)
|
||||||
@ -328,13 +339,15 @@ func (cs *ChainStore) reorgWorker(ctx context.Context, initialNotifees []ReorgNo
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.journal.AddEntry(journal.EventType{"sync", "head_change"}, map[string]interface{}{
|
journal.MaybeAddEntry(cs.journal, cs.evtTypes[evtTypeHeadChange], func() interface{} {
|
||||||
"from": r.old.Key(),
|
return journal.HeadChangeEvt{
|
||||||
"from_height": r.old.Height(),
|
From: r.old.Key(),
|
||||||
"to": r.new.Key(),
|
FromHeight: r.old.Height(),
|
||||||
"to_height": r.new.Height(),
|
To: r.new.Key(),
|
||||||
"rev_cnt": len(revert),
|
ToHeight: r.new.Height(),
|
||||||
"apply_cnt": len(apply),
|
RevertCount: len(revert),
|
||||||
|
ApplyCount: len(apply),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// reverse the apply array
|
// reverse the apply array
|
||||||
|
11
journal/sugar.go
Normal file
11
journal/sugar.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package journal
|
||||||
|
|
||||||
|
// MaybeAddEntry is a convenience function that evaluates if the EventType is
|
||||||
|
// enabled, and if so, it calls the supplier to create the entry and
|
||||||
|
// subsequently journal.AddEntry on the provided journal to record it.
|
||||||
|
func MaybeAddEntry(journal Journal, evtType EventType, supplier func() interface{}) {
|
||||||
|
if !evtType.Enabled() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
journal.AddEntry(evtType, supplier())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user