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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/core/interop/contract/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func Call(ic *interop.Context) error {
arr := stackitem.NewArray(args)
Copy link
Member

Choose a reason for hiding this comment

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

If you're serializing this is a useless variable.

arrCount := len(args)
valid := true
if _, err = ic.DAO.GetItemCtx().Serialize(arr, false); err != nil {
argBytes := []byte{}
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this to be initialized to zero-length slice? Also, stylistically I'd prefer

var (
)

block here since you declare a lot of things.

if argBytes, err = ic.DAO.GetItemCtx().Serialize(arr, false); err != nil {
arr = stackitem.NewArray([]stackitem.Item{})
valid = false
}
Expand All @@ -83,6 +84,7 @@ func Call(ic *interop.Context) error {
Hash: u,
Method: method,
Arguments: arr,
ArgumentsBytes: argBytes,
ArgumentsCount: uint32(arrCount),
IsValid: valid,
})
Expand Down
20 changes: 6 additions & 14 deletions pkg/core/state/notification_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,28 @@ type ContractInvocation struct {
Hash util.Uint160 `json:"contract_hash"`
Method string `json:"method"`
Arguments *stackitem.Array `json:"arguments"`
ArgumentsBytes []byte `json:"arguments_bytes"`
Copy link
Member

Choose a reason for hiding this comment

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

That's too many details for a public structure used in popular APIs. This should be hidden.

ArgumentsCount uint32 `json:"arguments_count"`
Copy link
Member

Choose a reason for hiding this comment

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

Why this one? In the optimistic case you have Arguments with some proper number of elements. In pessimistic, does it make any difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was that in case of Isvalid = false, then at least we have some information on the argument count.

as said in #3569 (comment)

I don't think we should throw away the complete invocation record because of a parameter violation. If it's recorded on chain then it was apparently still a valid invocation, regardless if we want to store all of the invocation details

I don't recall a hard necessity for this in my original use-case for this PR, but I think it's cheap to do and harder to add later (assuming the C# follows).

IsValid bool `json:"is_valid"`
Copy link
Member

Choose a reason for hiding this comment

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

Notice we never use snake_case in JSON structures, this should be something different. Also, from the Go perspective it's very convenient to have the default boolean (false) to follow regular use case. Like we use truncated for various find* results. Maybe truncated is applicable here too.

}

func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) {
ci.Hash.DecodeBinary(r)
ci.Method = r.ReadString()
args := stackitem.DecodeBinary(r)
if r.Err != nil {
return
}
arr, ok := args.Value().([]stackitem.Item)
if !ok {
r.Err = errors.New("array or Struct expected")
ci.ArgumentsBytes = r.ReadVarBytes()
si, err := stackitem.Deserialize(ci.ArgumentsBytes)
if err != nil {
return
}
ci.Arguments = stackitem.NewArray(arr)
ci.Arguments = si.(*stackitem.Array)
ci.ArgumentsCount = r.ReadU32LE()
ci.IsValid = r.ReadBool()
}

func (ci *ContractInvocation) EncodeBinaryWithContext(w *io.BinWriter, sc *stackitem.SerializationContext) {
ci.Hash.EncodeBinary(w)
w.WriteString(ci.Method)
b, err := sc.Serialize(ci.Arguments, false)
if err != nil {
w.Err = err
return
}
w.WriteBytes(b)
w.WriteVarBytes(ci.ArgumentsBytes)
w.WriteU32LE(ci.ArgumentsCount)
w.WriteBool(ci.IsValid)
}
Expand Down