-
Notifications
You must be signed in to change notification settings - Fork 37
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
node/meta: Use neo-go's new notification API #3164
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package meta | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/core/block" | ||
"github.com/nspcc-dev/neo-go/pkg/core/mpt" | ||
"github.com/nspcc-dev/neo-go/pkg/neorpc" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func (m *Meta) handleBlock(b *block.Header) error { | ||
h := b.Hash() | ||
ind := b.Index | ||
l := m.l.With(zap.Stringer("block hash", h), zap.Uint32("index", ind)) | ||
l.Debug("handling block") | ||
|
||
evName := objPutEvName | ||
m.cliM.RLock() | ||
res, err := m.ws.GetBlockNotifications(h, &neorpc.NotificationFilter{ | ||
Contract: &m.cnrH, | ||
Name: &evName, | ||
}) | ||
if err != nil { | ||
m.cliM.RUnlock() | ||
return fmt.Errorf("fetching %s block: %w", h, err) | ||
} | ||
m.cliM.RUnlock() | ||
|
||
if len(res.Application) == 0 { | ||
return nil | ||
} | ||
|
||
m.m.RLock() | ||
defer m.m.RUnlock() | ||
|
||
for _, n := range res.Application { | ||
ev, err := parseObjNotification(n) | ||
if err != nil { | ||
l.Error("invalid object notification received", zap.Error(err)) | ||
continue | ||
} | ||
|
||
s, ok := m.storages[ev.cID] | ||
if !ok { | ||
l.Debug("skipping object notification", zap.Stringer("inactual container", ev.cID)) | ||
continue | ||
} | ||
|
||
err = m.handleObjectNotification(s, ev) | ||
if err != nil { | ||
l.Error("handling object notification", zap.Error(err)) | ||
continue | ||
} | ||
|
||
l.Debug("handled object notification successfully", zap.Stringer("cID", ev.cID), zap.Stringer("oID", ev.oID)) | ||
} | ||
|
||
for _, st := range m.storages { | ||
// TODO: parallelize depending on what can parallelize well | ||
|
||
st.m.Lock() | ||
|
||
root := st.mpt.StateRoot() | ||
st.mpt.Store.Put([]byte{rootKey}, root[:]) | ||
p := st.path | ||
if st.opsBatch != nil { | ||
_, err := st.mpt.PutBatch(mpt.MapToMPTBatch(st.opsBatch)) | ||
if err != nil { | ||
st.m.Unlock() | ||
return fmt.Errorf("put batch for %d block to %q storage: %w", ind, p, err) | ||
} | ||
|
||
st.opsBatch = nil | ||
} | ||
|
||
st.m.Unlock() | ||
|
||
st.mpt.Flush(ind) | ||
} | ||
|
||
l.Debug("handled block successfully") | ||
|
||
return nil | ||
} | ||
|
||
func (m *Meta) blockFetcher(ctx context.Context, buff <-chan *block.Header) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case b := <-buff: | ||
err := m.handleBlock(b) | ||
if err != nil { | ||
m.l.Error("block handling failed", zap.Error(err)) | ||
continue | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to write docs incl. what behavior
Meta
expects for blocks w/o notifications - error of both nil?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what docs? this is literally simplification for tests. if there is either a test http server that can be mocked or we do not use tests at all, this interface does not exist. this is literally
rpcclient.WSClient
. docs will not save us if neo-go decides to change behavior. i do not plan to have any self written implementation here everThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ik why it's needed, idk how
GetBlockNotifications
interface behaves in mentioned case and wanna highlight thisit definitely wont change the behavior intentionally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will some reference to
rpcclient.WSClient
be enough in the comment? cause i do not understand you. nothing should implement it and it declares nothing for no one, it is literallyrpcclient.WSClient
but it is hard to mock it for tests. and i prefer this interface not to exist, but it would decrease coverage. i believe we will come tohttptest
package usage but not nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, u may state that this is a part of
WSClient
interface consumed byMeta
but 1st of all i wanna realize what is returned - 404 error, both nil or non-nil with empty fields?