-
Notifications
You must be signed in to change notification settings - Fork 81
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
Get block notifications API #3781
Conversation
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.
Nice one overall.
RPC client needs to be updated to support this as well. |
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.
A useful extension.
Please, ensure testing jobs are passing. Currently, unit-tests, project linter and DCO checks are failing. |
Hey guys, got some busy days ahead. I'll come back to this in one or two weeks max. Sorry for the delay |
dee62f4
to
cb76197
Compare
PR Updated. Changes:
Still pending:
About trigger filters: I don't know/don't have an opinion. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3781 +/- ##
==========================================
- Coverage 83.14% 82.99% -0.16%
==========================================
Files 335 335
Lines 46896 47056 +160
==========================================
+ Hits 38994 39054 +60
- Misses 6310 6399 +89
- Partials 1592 1603 +11 ☔ View full report in Codecov by Sentry. |
@@ -221,7 +235,6 @@ func (b *Block) GetExpectedBlockSizeWithoutTransactions(txCount int) int { | |||
return size | |||
} | |||
|
|||
// ToStackItem converts Block to stackitem.Item. |
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.
Useless change.
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.
Still relevant.
pkg/services/rpcsrv/util.go
Outdated
Container: container, | ||
NotificationEvent: evt, | ||
} | ||
if filter == nil || rpcevent.Matches(¬ificationComparatorFilter{ |
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.
filter == nil
check is excessive. rpcevent.Matche
perfectly handle this case.
Seems that we don't need it for now, so nothing should be done wrt this question. |
Please, format commits according to https://github.com/nspcc-dev/.github/blob/master/git.md#commits. See https://github.com/nspcc-dev/neo-go/pull/3787/commits for example. Also, please ensure your commits have valid signed-off-by signature. |
Add new RPC method to retrieve block notifications organized by trigger type. Signed-off-by: Ricardo Prado <[email protected]>
d012a6b
to
3d27ef8
Compare
@@ -221,7 +235,6 @@ func (b *Block) GetExpectedBlockSizeWithoutTransactions(txCount int) int { | |||
return size | |||
} | |||
|
|||
// ToStackItem converts Block to stackitem.Item. |
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.
Still relevant.
@@ -123,6 +124,55 @@ func TestPutGetBlock(t *testing.T) { | |||
require.Error(t, err) | |||
} | |||
|
|||
func TestGetTrimmedBlock(t *testing.T) { |
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.
Leftover, fails to test.
@@ -3149,3 +3149,8 @@ func (bc *Blockchain) GetStoragePrice() int64 { | |||
} | |||
return bc.contracts.Policy.GetStoragePriceInternal(bc.dao) | |||
} | |||
|
|||
// GetTrimmedBlock returns a block with only the header and transaction hashes. | |||
func (bc *Blockchain) GetTrimmedBlock(hash util.Uint256) (*block.TrimmedBlock, error) { |
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.
Needs to be fixed, fails to build.
|
||
// BlockNotifications represents notifications from a block organized by trigger type. | ||
type BlockNotifications struct { | ||
PrePersistNotifications []state.ContainedNotificationEvent `json:"prepersist,omitempty"` |
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.
I think we better have onpersist
instead of prepersist
in JSON, while pre
is technically more correct here we have on
used in trigger, method and many other places, so it'd be a bit more consistent this way.
// BlockNotifications represents notifications from a block organized by trigger type. | ||
type BlockNotifications struct { | ||
PrePersistNotifications []state.ContainedNotificationEvent `json:"prepersist,omitempty"` | ||
TxNotifications []state.ContainedNotificationEvent `json:"transactions,omitempty"` | ||
PostPersistNotifications []state.ContainedNotificationEvent `json:"postpersist,omitempty"` |
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.
You can still drop Notifications
from all of the field names, it's excessive. Actually following trigger names makes total sense here, OnPersist/Application/PostPersist like in https://github.com/nspcc-dev/neo-go/blob/8d728b4ec179e6354c21fc7e2c4f8a7c4df7312e/pkg/smartcontract/trigger/trigger_type.go
notifications := &result.BlockNotifications{} | ||
|
||
aers, err := s.chain.GetAppExecResults(block.Hash(), trigger.OnPersist) | ||
if err == nil && len(aers) > 0 { |
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.
Still relevant.
} | ||
|
||
aers, err = s.chain.GetAppExecResults(block.Hash(), trigger.PostPersist) | ||
if err == nil && len(aers) > 0 { |
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.
Also.
NotificationEvent: evt, | ||
} | ||
if rpcevent.Matches(¬ificationEventComparator{ | ||
filter: *filter, |
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.
Won't this panic on nil
filter? Probably something was a bit different when #3781 (comment) was made.
I can't push to linkd-academy:block-notifications, so this one is replaced with #3805 (which includes changes from this PR), thanks! |
Closes #3779.
It works but I don't know if this is the best way to do it.