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

[action] remove AbstractAction from all actions #4380

Merged
merged 4 commits into from
Sep 10, 2024
Merged

[action] remove AbstractAction from all actions #4380

merged 4 commits into from
Sep 10, 2024

Conversation

dustinxie
Copy link
Member

Description

following PR (#4297), this is to remove AbstractAction from all actions.

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

IntrinsicGas() (uint64, error)
SetEnvelopeContext(*AbstractAction)
Copy link
Member Author

Choose a reason for hiding this comment

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

now it will use AbstractAction in the envelope, not in each action, so this is no longer needed

Copy link
Member

Choose a reason for hiding this comment

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

Cost may serve as an optional implementation method. If the payload is not implemented, it will be price * intrinsicGas; if implemented, the result implemented by the payload will be used.

For example, execution should be price * gasLimit, and CreateStake should be price * intrinsicGas + stake amount.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cost is implemented by every action, and used by actpool
now the actions (like Execution, CreateStake) does not have the gasPrice field, so have to move the implementation up to the envelope struct

Copy link
Member

Choose a reason for hiding this comment

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

I see, but I prefer define an interface for payload to calc cost in envelop side, instead of calc by type explicitly

@@ -18,7 +18,7 @@ import (
type (
// Envelope defines an envelope wrapped on action with some envelope metadata.
Envelope interface {
Version() uint32
CommonAction() AbstractAction
Copy link
Member Author

Choose a reason for hiding this comment

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

so far, keep this as a struct
in the next PR, will convert to an interface (and have the 4 types of transactions implement it)

Copy link
Member

Choose a reason for hiding this comment

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

can we just inherit the AbstractAction? I didn't see the necessity of making it as a method

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, removed in latest code

if amount, ok := elp.payload.(hasAmount); ok {
cost.Add(cost, amount.Amount())
}
return cost, nil
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the same implementation as Cost() in each action now

@dustinxie dustinxie marked this pull request as ready for review September 5, 2024 05:46
Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

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

According to the description, AbstractAction was removed from all actions. What about Execution?

@@ -448,7 +448,7 @@ func (p *Protocol) handle(ctx context.Context, act action.Action, csm CandidateS
case *action.CandidateTransferOwnership:
rLog, tLogs, err = p.handleCandidateTransferOwnership(ctx, act, csm)
case *action.MigrateStake:
logs, tLogs, gasConsumed, gasToBeDeducted, err = p.handleStakeMigrate(ctx, act, csm)
logs, tLogs, gasConsumed, gasToBeDeducted, err = p.handleStakeMigrate(ctx, elp, csm)
Copy link
Collaborator

Choose a reason for hiding this comment

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

pass act, nonce, limit as parameters

actLogs := make([]*action.Log, 0)
transferLogs := make([]*action.TransactionLog, 0)
insGas, err := act.IntrinsicGas()
func (p *Protocol) handleStakeMigrate(ctx context.Context, elp action.Envelope, csm CandidateStateManager) ([]*action.Log, []*action.TransactionLog, uint64, uint64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

handleStakeMigrate(ctx, common, act, csm)
As the envelope has been opened, passing the common and act as separate parameters is more reasonable

Copy link
Member Author

Choose a reason for hiding this comment

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

now Envelope does not have a method to get the common AbstractAction part, we can do this once next PR converts AbstractAction to an interface and becomes a member var of Envelope
filed a TODO

case *CandidateRegister:
extraAmount = act.Amount()
if _, ok := elp.payload.(gasLimitForCost); ok {
gas = elp.GasLimit()
Copy link
Collaborator

Choose a reason for hiding this comment

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

in what case, gas limit is not calculated as cost?

Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

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

we need to review gas limit usage

Copy link

sonarcloud bot commented Sep 10, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
9.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 72.41379% with 72 lines in your changes missing coverage. Please review.

Project coverage is 75.26%. Comparing base (36f0d99) to head (771f53d).
Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
action/envelope.go 60.97% 16 Missing ⚠️
action/protocol/poll/consortium.go 0.00% 10 Missing ⚠️
api/coreservice.go 79.59% 6 Missing and 4 partials ⚠️
action/protocol/poll/staking_committee.go 0.00% 6 Missing ⚠️
action/protocol/rewarding/protocol.go 66.66% 5 Missing ⚠️
action/signedaction.go 73.68% 5 Missing ⚠️
action/candidate_endorsement.go 69.23% 3 Missing and 1 partial ⚠️
action/protocol/staking/handler_stake_migrate.go 80.00% 3 Missing ⚠️
action/candidate_activate.go 60.00% 2 Missing ⚠️
action/stake_migrate.go 33.33% 2 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4380      +/-   ##
==========================================
- Coverage   75.86%   75.26%   -0.60%     
==========================================
  Files         361      368       +7     
  Lines       30116    30018      -98     
==========================================
- Hits        22846    22594     -252     
- Misses       6134     6262     +128     
- Partials     1136     1162      +26     

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

@dustinxie dustinxie merged commit cc40d95 into master Sep 10, 2024
2 of 5 checks passed
@dustinxie dustinxie deleted the removeab branch September 10, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants