Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make journal pluggable; record deals, sealing, wdpost, mempool events #2455

Merged
merged 44 commits into from
Sep 14, 2020

Conversation

raulk
Copy link
Member

@raulk raulk commented Jul 17, 2020

Please merge with a squash


Addresses part of #2441; the other part (in-memory journal implementation) is hosted in Project Oni: filecoin-project/oni#226.

What has been done here

New journal events

  • Sealing state transition events are now recorded in the journal.
    • Required a change in storage-fsm to emit notifications.
  • Deal state transitions are now recorded in the journal.
  • Windowed PoSt events (run, abort, faults_processed, recoveries_processed, proofs_processed) are now recorded in the journal.
  • Mempool events (add, remove, repub) are now recorded in the journal. Add and remove are disabled by default.

Journal framework

  • Make the Journal not global; instead, use fx to inject it where needed.
  • Support typed journal events.
  • By default, Lotus constructs the filesystem-based journal, but it can be overridden with another implementation through a constructor option.
  • Ability to suppress/disable certain types of events, such as those known to be noisy and not relevant during production use, but important for testing (e.g. mempool add/drop).
  • In order to avoid runtime costs, suppressed event types need to be disabled during construction, by overriding the DisabledEvents fx key.
  • By default, we suppress the noisy mempool events. Oni tests will pass in an empty disabled set, so we get access to everything.
  • Sugar API function MaybeRecordEvent that lazily creates the event only if the EventType is enabled.

Example journal events

Sealing state machine transitions

{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:05:00.556940387Z","Data":{"SectorNumber":19,"SectorType":2,"From":"WaitSeed","After":"Committing","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:07:46.797337768Z","Data":{"SectorNumber":19,"SectorType":2,"From":"Committing","After":"CommitWait","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:11:59.258008229Z","Data":{"SectorNumber":19,"SectorType":2,"From":"CommitWait","After":"FinalizeSector","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:11:59.655317986Z","Data":{"SectorNumber":19,"SectorType":2,"From":"FinalizeSector","After":"Proving","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:44:00.581866465Z","Data":{"SectorNumber":20,"SectorType":2,"From":"WaitDeals","After":"Packing","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:44:13.940864008Z","Data":{"SectorNumber":20,"SectorType":2,"From":"Packing","After":"PreCommit1","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:45:03.216173326Z","Data":{"SectorNumber":20,"SectorType":2,"From":"PreCommit1","After":"PreCommit2","Error":""}}
{"System":"storage","Event":"sealing_states","Timestamp":"2020-08-11T15:46:30.365776445Z","Data":{"SectorNumber":0,"SectorType":0,"From":"","After":"Empty","Error":""}}

Windowed PoSt

{"System":"storage","Event":"wdpost","Timestamp":"2020-08-11T15:20:30.401238096Z","Data":{"State":"abort","Deadline":{"CurrentEpoch":10099,"PeriodStart":8419,"Index":28,"Open":10099,"Close":10159,"Challenge":10079,"FaultCutoff":10029},"Height":10158,"TipSet":[{"/":"bafy2bzacecv7qpj2o4i3wqiv2sia6sbuwiicequvvfwofybhownpdxjjll5d4"}]}}
{"System":"storage","Event":"wdpost","Timestamp":"2020-08-11T15:20:30.401491228Z","Data":{"State":"started","Deadline":{"CurrentEpoch":10159,"PeriodStart":8419,"Index":29,"Open":10159,"Close":10219,"Challenge":10139,"FaultCutoff":10089},"Height":10158,"TipSet":[{"/":"bafy2bzacecv7qpj2o4i3wqiv2sia6sbuwiicequvvfwofybhownpdxjjll5d4"}]}}
{"System":"storage","Event":"wdpost","Timestamp":"2020-08-11T15:20:30.403296622Z","Data":{"State":"recoveries_processed","Deadline":{"CurrentEpoch":10159,"PeriodStart":8419,"Index":29,"Open":10159,"Close":10219,"Challenge":10139,"FaultCutoff":10089},"Height":10158,"TipSet":[{"/":"bafy2bzacecv7qpj2o4i3wqiv2sia6sbuwiicequvvfwofybhownpdxjjll5d4"}],"Recoveries":{"Declarations":[],"MessageCID":null}}}
{"System":"storage","Event":"wdpost","Timestamp":"2020-08-11T15:20:30.403301022Z","Data":{"State":"faults_processed","Deadline":{"CurrentEpoch":10159,"PeriodStart":8419,"Index":29,"Open":10159,"Close":10219,"Challenge":10139,"FaultCutoff":10089},"Height":10158,"TipSet":[{"/":"bafy2bzacecv7qpj2o4i3wqiv2sia6sbuwiicequvvfwofybhownpdxjjll5d4"}],"Faults":{"Declarations":[],"MessageCID":null}}}

mpool

Add and remove events are disabled by default, but this is how add events look.

{"System":"mpool","Event":"add","Timestamp":"2020-08-11T15:35:42.640242628Z","Data":{"Action":"add","Messages":[{"Version":0,"To":"t01464","From":"t3q2sc3zvdhcwhuttajyv6zhlfmqfffan736fc552zu5m6vofneecmsbs5b3clrpgexklaqn75fgztim5y6rgq","Nonce":12673,"Value":"3727422619627069401","GasLimit":21651646,"GasFeeCap":"1064652776302","GasPremium":"4","Method":6,"Params":"igMZ1EjYKlgpAAGC4gOB6AIge/eO8WleRP1CBG7vb588+wOuByEifkZXavzVsjicJDEZH7uAGgAIu6P0AAAA","CID":{"/":"bafy2bzacebq3qfiynqc5oopqwmlhljsleybimkofuek5efthmfa7ang2hfa6i"}}]}}
{"System":"mpool","Event":"add","Timestamp":"2020-08-11T15:35:43.220132993Z","Data":{"Action":"add","Messages":[{"Version":0,"To":"t05","From":"t3qtgrsjee4tubfpzf2hjdmeqonkoz4c3llracv2lnwtanmkrexbtvcln7zvjwmptdblq67lkle66npbbnvbnq","Nonce":3351,"Value":"0","GasLimit":60881214,"GasFeeCap":"1088471905894","GasPremium":"2","Method":4,"Params":"gYGCi9gqWCgAAYHiA5IgIA/Jg0iXqR68K/HsuKblVjnlXjJzGmfzDFZ8XfYX5Hg4GgAEAAD0WDEDhM0ZJITk6BK/JdHSNhIOap2eC2tcQCrpbbTA1iokuGdRLb/NU2Y+Ywrh761LJ7zXQwC0DnhkewoJInBjaWRzIjogWwoJCXsKCQkJIi8iOiAiYmFmazJiemFjZWM1aWRuempxZHNubjM0ZmVnZnAzNGhlaHhyeXBmbmFmbHAycGxzeWplNGM1a2N3YnhsY3EiCgkJfQoJXQp9ChkzDRoACZ4ARQBQd12AQEBYYQKorCx9eeMPROqSS3EBVOkpB+D8ED3F9BFhdy/zLuENKoM5wpVzsczB3BqebR+LWIcScjNM4bDlT///WH/qlvkMTD5ac6E3gz1FzjmK9EhipOCZD0Qz146C1fmYq4DDNbg=","CID":{"/":"bafy2bzacebxx7hk7t6wpmehvo7ociw7tadntksjfwdyjnniygtqmulh7pamqo"}}]}}
{"System":"mpool","Event":"add","Timestamp":"2020-08-11T15:35:44.044902337Z","Data":{"Action":"add","Messages":[{"Version":0,"To":"t01045","From":"t3spbjekuheshmqj6gsz3fbrzozejq5aiyntqtaxuhptnemc5k4bolfgtyc76efrkwj4j6nz5vhlhf765i3fda","Nonce":26757,"Value":"3727361587939049590","GasLimit":14942648,"GasFeeCap":"335131587179","GasPremium":"2","Method":6,"Params":"igMZM23YKlgpAAGC4gOB6AIgf5Uw+fvcv1mECsio0Zoaqh44mYmGhagTyLH3TVIhzxUZH6mAGgAX0aL0AAAA","CID":{"/":"bafy2bzacecprq5z43bfucpg2hwh2faak7pjicz7jb6k74vaskqio5qjr5p5o6"}}]}}
{"System":"mpool","Event":"add","Timestamp":"2020-08-11T15:35:44.319591507Z","Data":{"Action":"add","Messages":[{"Version":0,"To":"t02220","From":"t3snngyn6annziz5heowxfkkd6jcpn5bizr2xkgptxxbatq2ttbuo56hl2xwnxsuqv3uj7nn6nzrxh73ufisha","Nonce":34002,"Value":"3727361587939049590","GasLimit":23323009,"GasFeeCap":"1","GasPremium":"1","Method":6,"Params":"igMaAASgqNgqWCkAAYLiA4HoAiCbrcfJNcDgfR5x8EXLAxkbPKhz0e+O427yQ0dFq8VQGhkiEYAaABfan/QAAAA=","CID":{"/":"bafy2bzacedzl7tmdqbvdct7ionck3ct5pibnxrrvt2cfocyvi7qcr65pqlarq"}}]}

Deals

{"System":"markets:storage:provider","Event":"deal_complete","Timestamp":"2020-08-11T15:43:00.600472498Z","Data":{"ID":18281,"Deal":{"Proposal":{"PieceCID":{"/":"baga6ea4seaqemba7nfrn6r2rv7x7q5uaaqrzdhyux3jpa2vvas4qqu7x2fae4hq"},"PieceSize":131072,"VerifiedDeal":false,"Client":"t3ulfykd6qimw63fbk6lcdjqnw6b7jqxwt2h7omwfdrawbssizutamjfax5g6iiqbkx22pt2yl2dtgk7vnj67a","Provider":"t03212","Label":"{\n\t\"pcids\": [\n\t\t{\n\t\t\t\"/\": \"bafk2bzacedmlz6vhpcemizgcax5almemh5o2f76vnnyk3r3dsofehi375rre2\"\n\t\t}\n\t]\n}\n","StartEpoch":13075,"EndEpoch":593058,"StoragePricePerEpoch":"2000000","ProviderCollateral":"0","ClientCollateral":"0"},"ClientSignature":{"Type":0,"Data":null},"ProposalCid":{"/":"bafyreicm35wkw6vrzbtpf3mj4zcquhi4h7qs6cmrfxatqagqcrqnm6hngy"},"AddFundsCid":null,"PublishCid":null,"Miner":"","Client":"12D3KooWJU6qqDH4DJtYfZrqiqb2dyNtgW2HNjhPmr6whSU6MgNb","State":4,"PiecePath":"","MetadataPath":"","SlashEpoch":0,"FastRetrieval":true,"Message":"","StoreID":null,"FundsReserved":"\u003cnil\u003e","Ref":{"TransferType":"graphsync","Root":{"/":"bafk2bzacedmlz6vhpcemizgcax5almemh5o2f76vnnyk3r3dsofehi375rre2"},"PieceCid":null,"PieceSize":0},"AvailableForRetrieval":false,"DealID":18281},"State":{"SectorStartEpoch":0,"LastUpdatedEpoch":0,"SlashEpoch":0},"Height":0}}

journal/memory.go Outdated Show resolved Hide resolved
journal/types.go Outdated Show resolved Hide resolved
@@ -0,0 +1,131 @@
package journal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this was copied as-is.

node/modules/storageminer.go Show resolved Hide resolved
Comment on lines 33 to 35
Proofs *WindowPoStEvt_Proofs `json:",omitempty"`
Recoveries *WindowPoStEvt_Recoveries `json:",omitempty"`
Faults *WindowPoStEvt_Faults `json:",omitempty"`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could actually be splintered into separate event types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth doing, window post journal will likely be the one of the most looked at

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -45,14 +46,25 @@ type ProviderNodeAdapter struct {

secb *sectorblocks.SectorBlocks
ev *events.Events

jrnl journal.Journal
evtTypes [4]journal.EventType
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For performance reasons, an array of journal.EventTypes is what I settled on as the lowest overhead, nicely encapsulated technique to initialize and store EventTypes during construction time, and index into them during runtime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code which is called here triggers codepaths which take minutes/hours on real networks, I don't think we need to worry about making this super fast too much.

@raulk raulk changed the title wip in-memory journal. make journal pluggable; record deals, sealing, wdpost, mempool events Aug 11, 2020
Base automatically changed from next to master August 19, 2020 00:14
Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long on this.

Looks pretty good, just a couple of comments


func (n *nilJournal) RegisterEventType(_, _ string) EventType { return EventType{} }

func (n *nilJournal) RecordEvent(_ EventType, _ func() interface{}) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we scream loudly in logs when something calls this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. This journal is designed for testing or for running stuff outside the lotus daemon (e.g. CLI tools). Things will call it all the time; this journal just no-ops. Maybe we can scream loudly when registering events, but I think it adds no value.

@@ -45,14 +46,25 @@ type ProviderNodeAdapter struct {

secb *sectorblocks.SectorBlocks
ev *events.Events

jrnl journal.Journal
evtTypes [4]journal.EventType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code which is called here triggers codepaths which take minutes/hours on real networks, I don't think we need to worry about making this super fast too much.

node/builder.go Outdated Show resolved Hide resolved
node/modules/storageminer.go Show resolved Hide resolved
node/modules/storageminer.go Show resolved Hide resolved
}

// SealingStateEvt is a journal event that records a sector state transition.
type SealingStateEvt struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would live inside the sealing package. We want to move sealing.New construction to DI, but it's somewhat entangled with the Miner struct here. We should try to not make this worse

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the journalling itself, or just the struct? If it's the first, we could do that, but that means that the theoretically external sealing package would now depend on Lotus' journal interface, unless we re-declare it there. This would be a very simple refactor to do going forward, when compared to all the detangling that needs to happen anyway, so I wouldn't wanna stall on this right here right now.

storage/wdpost_run.go Outdated Show resolved Hide resolved
storage/wdpost_run.go Outdated Show resolved Hide resolved
storage/wdpost_run.go Show resolved Hide resolved
Comment on lines 33 to 35
Proofs *WindowPoStEvt_Proofs `json:",omitempty"`
Recoveries *WindowPoStEvt_Recoveries `json:",omitempty"`
Faults *WindowPoStEvt_Faults `json:",omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth doing, window post journal will likely be the one of the most looked at

@raulk raulk requested a review from magik6k September 2, 2020 18:46
@raulk
Copy link
Member Author

raulk commented Sep 2, 2020

Note that I don’t have a miner, so I haven’t tested this to the degree I'd be satisfied. Please test with a miner of yours before merging! There may be hidden bugs that weren’t caught by tests.

Copy link
Member

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets doooo ittttt

@whyrusleeping whyrusleeping merged commit b212368 into master Sep 14, 2020
@whyrusleeping whyrusleeping deleted the inmem-journal branch September 14, 2020 18:17
@RobQuistNL
Copy link
Contributor

This is freaking awesome <3

@raulk raulk mentioned this pull request Jan 18, 2021
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants