Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Refactoring Proposal for IFeeCalculator #3118

Closed
riemannulus opened this issue Apr 28, 2023 · 0 comments
Closed

Refactoring Proposal for IFeeCalculator #3118

riemannulus opened this issue Apr 28, 2023 · 0 comments
Assignees

Comments

@riemannulus
Copy link
Member

(영어 이후에 한국어가 따라옵니다.)

Problem Statement

Currently, IFeeCalculator is too rigid for the amount of work it does and is difficult to adapt to potential issues.

  • IFeeCalculator.Calculate only takes in IAction as an argument, making it necessary to manage base fees separately if desired.
  • Modifying IFeeCalculator would alter the results of previous blocks.
  • IFeeCalculator being an interface forces unnecessary implementation of unused classes.
  • Information necessary for calculating base fees, etc. is difficult to include in IFeeCalculator as ActionEvaluator calling IFeeCalculator cannot access the chain.

Moreover, the fee collection through IFeeCalculator is implemented inside ActionEvaluator, resulting in the following problems:

  • It is unknown whether fees can actually be collected during the GatherTransactionToPropose() stage.
  • ActionEvaluator implicitly causes state transitions other than executing actions.

Goals and Proposal

IFeeCalculator

Goals

IFeeCalculator contains more diverse information, and is called through IVariableFeeCalculator to select the proper IFeeCalculator for the block index.

Proposal

  • IFeeCalculator has the following interface.
delegate FungibleAssetValue DelegateActionFeeCalculator(IAction target)
delegate FungibleAssetValue DelegateBaseFeeCalculator(Block<T> previous)
delegate FungibleAssetValue DelegateFeeCalculator()

interface IFeeCalculator:
  DelegateActionFeeCalculator ActionFeeCal
  DelegateBaseFeeCalculator BaseFeeCal

  DelegateFeeCalculator Calculate

  • IVariableFeeCalculator has the following interface.
interface IVariableFeeCalculator:
  DelegateFeeCalculator Get(IVariableFeeCalculatorContext context)
  IVariableFeeCalculator Add(IFeeCalculator cal)

IFeeCollector

Goals

IFeeCollector verifies whether fees can be collected through IFeeCalculator-derived FAV, and performs the following actions:

  • Verifies whether the fee for the relevant Tx can be collected.
  • Collects the fee for the Tx and returns ActionEvaluation.
    • If collection fails, all actions in the relevant Tx are considered failed.

Proposal

  • IFeeCollector has the following interface.
interface IFeeCollector:
  bool Collectable(Transaction<T> tx)
  ImmutableList<ActionEvaluation> Collect(Transaction<T> tx)

Conclusion

This proposal suggests a refactoring of the current IFeeCalculator and IFeeCollector interfaces to make them more flexible and adaptable to potential issues.


문제 인식

현재 IFeeCalculator 는 너무나도 하는 일에 비해 경직되어 있고, 여러 일어날 수 있는 문제에 대해 대응하기 어렵습니다.

  • IFeeCalculator.CalculateIAction 만을 인자로 받고 있어 base fee 등을 넣고 싶다면 따로 관리해야 합니다.
  • IFeeCalculator 를 수정하게 되면 이전 블록의 연산 결과가 달라지게 됩니다.
  • IFeeCalculator 가 인터페이스로 되어 있어, 필요 없는 구현체 구현을 강제하고 있습니다.
  • IFeeCalculator 가 불리는 ActionEvaluator 에서는 체인에 접근할 수 없어 base fee 등을 계산하기 위한 정보를 넣어주기가 어렵습니다.

또한, IFeeCalculator 를 통한 요금 징수 부분이 ActionEvaluator 안쪽에 구현되어 있어 다음과 같은 문제가 있습니다.

  • 요금이 실제로 징수 가능한지 GatherTransactionToPropose() 단계에서 알 수가 없습니다.
  • ActionEvaluator 가 Action을 실행하는 것 이외에 다른 상태 전이를 암시적으로 일으킵니다.

목표 및 제안

IFeeCalculator

목표

IFeeCalculator 가 더 다양한 정보를 담고 있고, 이를 IVariableFeeCalculator 를 통해 블록 인덱스에 맞는 IFeeCalculator 를 호출하는 형태를 가집니다.

제안

  • IFeeCalculator 가 다음과 같은 인터페이스를 가집니다.
delegate FungibleAssetValue DelegateActionFeeCalculator(IAction target)
delegate FungibleAssetValue DelegateBaseFeeCalculator(Block<T> previous)
delegate FungibleAssetValue DelegateFeeCalculator()

interface IFeeCalculator:
  DelegateActionFeeCalculator ActionFeeCal
  DelegateBaseFeeCalculator BaseFeeCal

  DelegateFeeCalculator Calculate
  • IVariableFeeCalculator 는 다음과 같은 인터페이스를 가집니다.
interface IVariableFeeCalculator:
  DelegateFeeCalculator Get(IVariableFeeCalculatorContext context)
  IVariableFeeCalculator Add(IFeeCalculator cal)

IFeeCollector

목표

IFeeCollectorIFeeCalculator 를 통해 얻어 진 FAV를 가지고 다음과 같은 일을 수행합니다.

  • 해당 Tx의 요금이 징수 가능한지 확인합니다.
  • Tx의 요금을 징수하고 ActionEvaluation 을 반환합니다.
    • 징수에 실패했다면 해당 Tx에 포함된 모든 Action을 실패처리합니다.

제안

  • IFeeCollector 는 다음과 같은 인터페이스를 가집니다.
interface IFeeCollector:
  bool Collectable(Transaction<T> tx)
  ImmutableList<ActionEvaluation> Collect(Transaction<T> tx)
@riemannulus riemannulus self-assigned this Apr 28, 2023
@planetarium planetarium locked and limited conversation to collaborators Apr 28, 2023
@longfin longfin converted this issue into discussion #3119 Apr 28, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant