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

Adding event limit per transaction #128

Merged
merged 43 commits into from
Dec 11, 2020
Merged

Conversation

ramtinms
Copy link
Member

@ramtinms ramtinms commented Nov 6, 2020

This PR introduces these changes

  • returning errors for emitEvent method call
  • moving event conversion into emitEvent (this facilitates to measure the size of events as we go and stop earlier instead of collecting all and compute at the end) . This results the env to store flow.Events instead of cadence.Events
  • add txIndex to transaction environment instead of passing it to the method calls (e.g. convertEvents)
  • adding the event size limit to the context (with default to 128KB)
  • adding a flag for collecting logs and default to fall
  • adding a new error type for event limits

Steps remaining

  • bump the cadence version to support even error return
  • update the emulator to set log flag to true (PR is here )

@ramtinms ramtinms requested a review from m4ksio November 17, 2020 17:41
@ramtinms ramtinms changed the title [WIP] Add event limit per transaction Adding event limit per transaction Nov 20, 2020
@ramtinms ramtinms marked this pull request as ready for review November 21, 2020 00:04
integration/go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@psiemens psiemens left a comment

Choose a reason for hiding this comment

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

Great idea to move the event construction inside FVM 👍 I never quite liked that before

fvm/account.go Outdated Show resolved Hide resolved
fvm/context.go Outdated Show resolved Hide resolved
fvm/env.go Show resolved Hide resolved
fvm/errors.go Outdated Show resolved Hide resolved
fvm/errors.go Outdated Show resolved Hide resolved
Copy link
Contributor

@janezpodhostnik janezpodhostnik left a comment

Choose a reason for hiding this comment

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

LGTM. Just one minor comment.

fvm/env.go Outdated Show resolved Hide resolved
Copy link
Contributor

@psiemens psiemens left a comment

Choose a reason for hiding this comment

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

LGTM

if err != nil {
return nil, errors.New("error decoding events")
}
addr = flow.Address(data.(cadence.Event).Fields[0].(cadence.Address))
Copy link
Member

Choose a reason for hiding this comment

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

Use flow.AccountCreatedEvent(event).Address() instead

Copy link
Member Author

Choose a reason for hiding this comment

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

AccountCreatedEvent doesn't exist in flow, I guess flowsdk has some functionality

Copy link
Member Author

@ramtinms ramtinms Dec 10, 2020

Choose a reason for hiding this comment

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

hmm, I can't add it to models, it adds circular dependencies

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I thought this was declared in the models, nevermind then

address := flow.Address(tx.Events[0].Fields[0].(cadence.Address))
data, err := jsoncdc.Decode(tx.Events[0].Payload)
require.NoError(t, err)
address := flow.Address(data.(cadence.Event).Fields[0].(cadence.Address))
Copy link
Member

Choose a reason for hiding this comment

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

Use flow.AccountCreatedEvent(event).Address() instead here, and in the other cases below


func (e *hostEnv) GenerateUUID() uint64 {
uuid, err := e.uuidGenerator.GenerateUUID()
payload, err := jsoncdc.Encode(event)
Copy link
Member

Choose a reason for hiding this comment

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

Should we really measure size by encoding to the very verbose JSON format?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, that's how we store them right now and deliver them to users, so I kept the JSON encoding so users can have some measures of how big the events are. We increase the limit in the future when we store things more binary.

Copy link
Member

@turbolent turbolent Dec 10, 2020

Choose a reason for hiding this comment

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

Oh, I thought we store them as Cadence interpreter values, like in the account storage. It would be great if we could switch, I don't even think the JSON encoding is deterministic? But that's for another PR - If we store events as JSON, then we should measure it as that 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't even think the JSON encoding is deterministic
thats a good point, we def need to change for event verification

@ramtinms ramtinms merged commit 115ccee into master Dec 11, 2020
@ramtinms ramtinms deleted the ramtin/adding-event-limiter branch December 11, 2020 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants