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

*: add invocations to applicationlog #3569

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

ixje
Copy link
Contributor

@ixje ixje commented Sep 3, 2024

Problem

neo-project/neo#3386

Solution

Implement as extension. Moved the discussion from Dora's backend PR to here

To do

  • copy arguments to avoid modifications
  • limit the total number of argument stack items in a single transaction (for safety)
  • make this a configurable feature
  • include native contract calls

Do we want to limit the stack item depth (think MaxJSONDepth) or are we content with just limiting the total stack arguments?

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

A good prototype, but I have several design questions that we should solve before review.

pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
@AnnaShaleva
Copy link
Member

@roman-khimov, I think we need some third opinion on these topics.

@roman-khimov
Copy link
Member

How about System.Runtime.LoadScript calls, btw?

@AnnaShaleva
Copy link
Member

How about System.Runtime.LoadScript calls

It leads to new execution context creation, thus it's a valid part of invocation tree. But is this information useful in practice? Dynamic invocations are identified by hash160 of the loaded script, as a result user can't get this script because he knows only its hash. But still we may include dynamic invocations into the resulting Invocations tree with some special field like isContractCall: false.

@ixje ixje force-pushed the applog-invocations branch from f4e91f5 to dfd5c9b Compare October 31, 2024 09:03
@ixje
Copy link
Contributor Author

ixje commented Oct 31, 2024

Picking this up again. I rebased the branch onto latest master and processed some of the feedback. In particular

  • use stackitem.Serialize instead of deepcopy and re-use the results when storing the data
  • make the behaviour configurable through a SaveInvocations config option

Note; It was unclear to me based on #3569 (comment) if I should have made it a tree or keep it flat. I kept it flat for now.

If the feature is enabled the applicationlog output looks as follows

"invocations": [
                    {
                        "contract_hash": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                        "method": "transfer",
                        "arguments": {
                            "type": "Array",
                            "value": [
                                {
                                    "type": "ByteString",
                                    "value": "krOcd6pg8ptXwXPO2Rfxf9Mhpus="
                                },
                                {
                                    "type": "ByteString",
                                    "value": "AZelPVEEY0csq+FRLl/HJ9cW+Qs="
                                },
                                {
                                    "type": "Integer",
                                    "value": "1000000000000"
                                },
                                {
                                    "type": "Any"
                                }
                            ]
                        },
                        "arguments_count": 4,
                        "is_valid": true
                    }
                ]

and in disabled state it returns

"invocations": []

I'm looking for feedback on the above before taking care of covering System.Runtime.LoadScript calls

@ixje ixje requested a review from AnnaShaleva October 31, 2024 09:43
@ixje
Copy link
Contributor Author

ixje commented Nov 14, 2024

@AnnaShaleva can this PR also get some review love please

@ixje ixje marked this pull request as ready for review November 19, 2024 10:26
@ixje ixje requested a review from roman-khimov November 19, 2024 10:27
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

I don't see any limits for the overall size of saved data. While the feature is optional we still need to protect node from abuse.

pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
@ixje ixje requested a review from roman-khimov November 20, 2024 14:17
@ixje
Copy link
Contributor Author

ixje commented Dec 1, 2024

ping

@ixje
Copy link
Contributor Author

ixje commented Dec 3, 2024

I feel there is a lot of resistance against this PR, but I can't really tell why. Other PRs I opened (later than this one, like #3674 and #3677) were swiftly reviewed (multiple times). This one however takes 2-3 weeks per update to get another response despite multiple pings.

Can any of you @AnnaShaleva @roman-khimov elaborate please? If I understand where this resistance is coming from I can perhaps do something about it.

@roman-khimov
Copy link
Member

@ixje, zero resistance. Sorry, it's just that there are too many things to handle at once. @AnnaShaleva will get back to it soon.

pkg/config/ledger_config.go Outdated Show resolved Hide resolved
pkg/config/ledger_config.go Show resolved Hide resolved
pkg/core/interop/context.go Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/interop/context.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
@AnnaShaleva
Copy link
Member

@ixje sorry for the delay. Actually, when we don't need #3569 (comment) and #3569 (comment) to be fixed, there are only a couple of non-critical issues left to be fixed, so the PR is almost ready and looks good.

@ixje
Copy link
Contributor Author

ixje commented Jan 2, 2025

@AnnaShaleva some RPC server tests and TestNEO_CommitteeEvents are failing due to changes requested by you in this comment. If I do write this 1 byte for the length then they pass (with some small updates where necessary).

I've spend some time trying to understand why TestNEO_CommitteeEvents is failing and for some reason the data fetched from the dao does contain the execution events, despite the body of this logic never being called (as per breakpoints not hitting in the debugger)

	if invocLen := len(aer.Invocations); invocLen > 0 {
		w.WriteVarUint(uint64(invocLen))
		for i := range aer.Invocations {
			aer.Invocations[i].EncodeBinaryWithContext(w, sc)
		}
	}

Putting a breakpoint in EncodeBinaryWithContext of ContractInvocation is also not hit. I'm not sure yet what/where I'm overlooking something. Any help/insight there is appreciated.

@ixje ixje requested a review from AnnaShaleva January 2, 2025 12:51
docs/rpc.md Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 62.39316% with 44 lines in your changes missing coverage. Please review.

Project coverage is 83.04%. Comparing base (e8b8c1a) to head (4b2ee9a).
Report is 221 commits behind head on master.

Files with missing lines Patch % Lines
pkg/core/state/contract_invocation.go 76.92% 10 Missing and 5 partials ⚠️
pkg/core/state/notification_event.go 20.00% 9 Missing and 3 partials ⚠️
pkg/core/interop/contract/call.go 9.09% 9 Missing and 1 partial ⚠️
pkg/core/blockchain.go 33.33% 3 Missing and 1 partial ⚠️
pkg/core/dao/dao.go 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3569      +/-   ##
==========================================
- Coverage   83.20%   83.04%   -0.17%     
==========================================
  Files         334      336       +2     
  Lines       46488    47005     +517     
==========================================
+ Hits        38681    39034     +353     
- Misses       6234     6373     +139     
- Partials     1573     1598      +25     

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

docs/rpc.md Outdated Show resolved Hide resolved
pkg/core/dao/dao_test.go Outdated Show resolved Hide resolved
docs/rpc.md Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation_test.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation_test.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
@AnnaShaleva
Copy link
Member

Everything is almost done, so once finished, please, format commits according to https://github.com/nspcc-dev/.github/blob/master/git.md#commits and add a proper signoff to the commit messages.

@ixje
Copy link
Contributor Author

ixje commented Jan 23, 2025

Everything is almost done, so once finished, please, format commits according to https://github.com/nspcc-dev/.github/blob/master/git.md#commits and add a proper signoff to the commit messages.

I'll wait with the squashing and signoff until everything is really approved. I thought I was close a couple of times before and then the next review requests changes over parts that 'passed' the previous reviews.

@ixje ixje requested a review from AnnaShaleva January 23, 2025 10:55
pkg/core/state/contract_invocation.go Outdated Show resolved Hide resolved
pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
pkg/core/interop/contract/call.go Outdated Show resolved Hide resolved
@AnnaShaleva AnnaShaleva added this to the v0.108.0 milestone Jan 24, 2025
@AnnaShaleva AnnaShaleva added rpc RPC server and client enhancement Improving existing functionality labels Jan 24, 2025
@ixje ixje requested a review from AnnaShaleva January 24, 2025 11:57
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

LGTM. Let's squash and reformat commits.

pkg/core/state/notification_event.go Outdated Show resolved Hide resolved
Add setting to include smart contract invocations data to the applicationlog.
Original issue at neo-project/neo#3386

Signed-off-by: ixje <erik@coz.io>
@ixje ixje force-pushed the applog-invocations branch from dd173d8 to 4b2ee9a Compare January 24, 2025 14:51
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

Congratulations!

Let's wait for the testing jobs to finish before the merge.

@AnnaShaleva AnnaShaleva merged commit 7ba8048 into nspcc-dev:master Jan 24, 2025
32 of 34 checks passed
@ixje
Copy link
Contributor Author

ixje commented Jan 24, 2025

🎉
Very happy to get this merged in time for the 0.108 release. Thanks for all the reviews, this was a lengthy one 💦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving existing functionality rpc RPC server and client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants