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

Support plugins #2051

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Support plugins #2051

wants to merge 17 commits into from

Conversation

rianhughes
Copy link
Contributor

@rianhughes rianhughes commented Aug 14, 2024

This PR implements plugin support. Any plugin that follows the JunoPlugin interface can plug into Juno.

type JunoPlugin interface {
	Init() error
	Shutdown() error // Todo: Currently this function will never be called.
	NewBlock(block *core.Block, stateUpdate *core.StateUpdate, newClasses map[felt.Felt]core.Class) error
	// The state is reverted by applying a write operation with the reverseStateDiff's StorageDiffs, Nonces, and ReplacedClasses,
	// and a delete option with its DeclaredV0Classes, DeclaredV1Classes, and ReplacedClasses.
	RevertBlock(from, to *BlockAndStateUpdate, reverseStateDiff *core.StateDiff) error
}

Whenever Juno syncs a new block, the block, state-update and classes are sent to the plugin. Specifically, NewBlock() is called
NewBlock(block *core.Block, stateUpdate *core.StateUpdate, newClasses map[felt.Felt]core.Class) error

Whenver Juno reverts a block, it will send the block and state-updateof the current height "N", the reverted height "N-1", as well as the "reverse state diff" that brings you from N to N-1. Specifically, RevertBlock() is called
RevertBlock(from, to *BlockAndStateUpdate, reverseStateDiff *core.StateDiff) error

Note: the code coverage is below the threshold. The main chunk of code that hasn't been tested is the Load() function. A simple plugin that only prints when a function has been called can be quite large (~37Mb+), so it doesn't seem feasible to include a dummy plugin/.so file for the purpose of increasing the code coverage. However, the Load function was tested manually and it seems to work just fine (see here for example plugin)

@rianhughes rianhughes force-pushed the rianhughes/plugin2 branch 2 times, most recently from 01f84c5 to c08159a Compare August 14, 2024 08:49
@rianhughes rianhughes marked this pull request as ready for review August 14, 2024 08:51
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

Attention: Patch coverage is 45.09804% with 56 lines in your changes missing coverage. Please review.

Project coverage is 78.26%. Comparing base (9a3f263) to head (e387614).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
sync/sync.go 51.21% 12 Missing and 8 partials ⚠️
node/node.go 15.38% 10 Missing and 1 partial ⚠️
plugin/plugin.go 0.00% 11 Missing ⚠️
core/state.go 58.33% 6 Missing and 4 partials ⚠️
blockchain/blockchain.go 66.66% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2051      +/-   ##
==========================================
- Coverage   78.45%   78.26%   -0.19%     
==========================================
  Files         100      103       +3     
  Lines        9240     9294      +54     
==========================================
+ Hits         7249     7274      +25     
- Misses       1353     1377      +24     
- Partials      638      643       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rianhughes rianhughes added this to the v0.12.1 milestone Aug 23, 2024
@rianhughes rianhughes changed the title Rianhughes/plugin2 Support plugins Aug 23, 2024
sync/sync.go Outdated Show resolved Hide resolved
@rianhughes rianhughes marked this pull request as draft September 24, 2024 14:15
@rianhughes rianhughes marked this pull request as ready for review September 25, 2024 08:07
blockchain/blockchain.go Outdated Show resolved Hide resolved
@weiihann
Copy link
Contributor

I'd suggest to add some documentations so that users are aware of this feature

cmd/juno/juno.go Outdated Show resolved Hide resolved
plugin/plugin.go Outdated Show resolved Hide resolved
plugin/plugin_test.go Outdated Show resolved Hide resolved
sync/sync.go Show resolved Hide resolved
sync/sync.go Outdated Show resolved Hide resolved
sync/sync.go Outdated Show resolved Hide resolved
sync/sync.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

5 participants