Refactoring Proposal for IFeeCalculator #3119
Replies: 6 comments
-
|
The plan is complicated. And there has been talk and I agree that the actual problem perception seems We will make additional suggestions later. |
Beta Was this translation helpful? Give feedback.
-
|
I bring a new proposal about refactoring classDiagram
%% Interfaces
class IAction{
+Name(): Bencodex.Types.String
+Values(): Bencodex.Types.IValue
+Types(): Bencodex.Types.String
}
class IAccountStateView {
+GetState(Address)
+GetStates(Addresses)
+GetBalance(Address, Currency)
+GetTotalSupply(Currency)
}
class IAccountStateDelta {
+UpdatedAddresses()
+StateUpdatedAddresses()
+UpdatedFungibleAssets()
+TotalSupplyUpdatedCurrency()
+SetState(Address, IValue)
+MintAsset(Address, FAV)
+TransferAsset(Address, Address, FAV, bool)
+BurnAsset(Address, FAV)
}
class IGasStateView {
+UsedGas(): UInt256
}
class IGasStateDelta {
~AddGas(UInt256)
~SetGas(UInt256)
~SetGasLimit(UInt256)
}
class IValidatorStateView {
+GetValidatorSet()
}
class IValidatorStateDelta {
+SetValidator()
}
class IStateDelta {
}
class IStateDeltaImpl {
}
class IPreEvaluationBlock {
+Transactions(): IImmutableSet~ITransaction~
+BaseGasPrice(): FungibleAssetValue
+GasLimit(): UInt256
}
class ITransaction {
+Actions(): ImmutableList~IAction~
+GasLimit(): UInt256
+MaxGasPrice(): FungibleAssetValue
+CommissionGasPrice(): FungibleAssetValue
}
class IActionEvaluator {
-IReadOnlyList~IAction~ BeginBlocks
-IReadOnlyList~IAction~ EndBlocks
+Execute(IPreEvaluationBlock): IReadOnlyList~IActionEvaluation~
+EstimateGas(ITransaction): IReadOnlyList~IActionEvaluation~
}
class IActionEvaluation {
+Action(): IValue
+OutputStates(): IStateDelta
+InputContext(): IActionContext
}
class IActionRenderer {
+RenderBlock(Block prev, Block next)
+RenderAction(IAction, IActionContext, IStateDelta)
+RenderActionError(IAction, IActionContext, Exception)
+RenderBlockEnd(Block prev, Block next)
}
%% Relations
IActionEvaluator --> IPreEvaluationBlock
IActionEvaluator --> IActionEvaluation
IActionEvaluation --> IStateDelta
IActionRenderer --> IActionEvaluation
IPreEvaluationBlock o-- ITransaction
ITransaction o-- IAction
IAccountStateView <|-- IAccountStateDelta
IGasStateView <|-- IGasStateDelta
IValidatorStateView <|-- IValidatorStateDelta
IAccountStateDelta <|-- IStateDelta
IGasStateDelta <|-- IStateDelta
IValidatorStateDelta <|-- IStateDelta
IStateDelta ..|> IStateDeltaImpl
Note new interface |
Beta Was this translation helpful? Give feedback.
-
|
Psuedo code on these interfaces. |
Beta Was this translation helpful? Give feedback.
-
|
The basic idea is when calling API on If the action is successfully executed, refund fee by unused gas. (https://gist.github.com/riemannulus/4f213628bba047974e08586a4297e394#file-actionevaluator-cs-L56-L58) |
Beta Was this translation helpful? Give feedback.
-
|
cc. @libplanet |
Beta Was this translation helpful? Give feedback.
-
|
A few API changes about suggestion by @longfin classDiagram
%% Interfaces
class IAction{
+Values(): Bencodex.Types.IValue
+Types(): Bencodex.Types.String
}
class IAccountStateView {
+GetState(Address)
+GetStates(Addresses)
+GetBalance(Address, Currency)
+GetTotalSupply(Currency)
}
class IAccountStateDelta {
+UpdatedAddresses()
+StateUpdatedAddresses()
+UpdatedFungibleAssets()
+TotalSupplyUpdatedCurrency()
+SetState(Address, IValue)
+MintAsset(Address, FAV)
+TransferAsset(Address, Address, FAV, bool)
+BurnAsset(Address, FAV)
}
class IGasStateDelta {
~AddGas(long, Address)
~SetGas(long, Address)
~SetGasLimit(long, Address)
~UsedGas(Address): long
~AvailableGas(Address): long
}
class IValidatorStateView {
+GetValidatorSet()
}
class IValidatorStateDelta {
+SetValidator()
}
class IActionContext {
+PreviousStates(): IAccountStateDelta
+UsedGas(Address): long
+AvailableGas(Address): long
}
class IPreEvaluationBlock {
+Transactions(): IImmutableSet~ITransaction~
+BaseGasPrice(): FungibleAssetValue
+GasLimit(): long
}
class ITransaction {
+Actions(): ImmutableList~IAction~
+GasLimit(): long
+MaxGasPrice(): FungibleAssetValue
+CommissionGasPrice(): FungibleAssetValue
}
class IActionEvaluator {
-IReadOnlyList~IAction~ BeginBlocks
-IReadOnlyList~IAction~ EndBlocks
+Execute(IPreEvaluationBlock): IReadOnlyList~IActionEvaluation~
+EstimateGas(ITransaction): IReadOnlyList~IActionEvaluation~
}
class IActionEvaluation {
+Action(): IValue
+OutputStates(): IAccountStateDelta
+InputContext(): IActionContext
}
class IActionRenderer {
+RenderBlock(Block prev, Block next)
+RenderAction(IAction, IActionContext, IAccountStateDelta)
+RenderActionError(IAction, IActionContext, Exception)
+RenderBlockEnd(Block prev, Block next)
}
%% Relations
IActionEvaluator --> IPreEvaluationBlock
IActionEvaluator --> IActionEvaluation
IActionEvaluation --> IAccountStateDelta
IActionContext --> IAccountStateDelta
IActionEvaluation --> IActionContext
IActionRenderer --> IActionEvaluation
IPreEvaluationBlock o-- ITransaction
ITransaction o-- IAction
IAccountStateView <|-- IAccountStateDelta
IValidatorStateView <|-- IValidatorStateDelta
IAccountStateDelta ..|> IAccountStateDeltaImpl
IGasStateDelta ..|> IAccountStateDeltaImpl
IValidatorStateDelta ..|> IAccountStateDeltaImpl
Note change |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
(영어 이후에 한국어가 따라옵니다.)
Problem Statement
Currently,
IFeeCalculatoris too rigid for the amount of work it does and is difficult to adapt to potential issues.IFeeCalculator.Calculateonly takes inIActionas an argument, making it necessary to manage base fees separately if desired.IFeeCalculatorwould alter the results of previous blocks.IFeeCalculatorbeing an interface forces unnecessary implementation of unused classes.IFeeCalculatorasActionEvaluatorcallingIFeeCalculatorcannot access the chain.Moreover, the fee collection through
IFeeCalculatoris implemented insideActionEvaluator, resulting in the following problems:GatherTransactionToPropose()stage.ActionEvaluatorimplicitly causes state transitions other than executing actions.Goals and Proposal
IFeeCalculator
Goals
IFeeCalculatorcontains more diverse information, and is called throughIVariableFeeCalculatorto select the properIFeeCalculatorfor the block index.Proposal
IFeeCalculatorhas the following interface.IVariableFeeCalculatorhas the following interface.IFeeCollector
Goals
IFeeCollectorverifies whether fees can be collected throughIFeeCalculator-derived FAV, and performs the following actions:ActionEvaluation.Proposal
IFeeCollectorhas the following interface.Conclusion
This proposal suggests a refactoring of the current
IFeeCalculatorandIFeeCollectorinterfaces to make them more flexible and adaptable to potential issues.문제 인식
현재
IFeeCalculator는 너무나도 하는 일에 비해 경직되어 있고, 여러 일어날 수 있는 문제에 대해 대응하기 어렵습니다.IFeeCalculator.Calculate는IAction만을 인자로 받고 있어 base fee 등을 넣고 싶다면 따로 관리해야 합니다.IFeeCalculator를 수정하게 되면 이전 블록의 연산 결과가 달라지게 됩니다.IFeeCalculator가 인터페이스로 되어 있어, 필요 없는 구현체 구현을 강제하고 있습니다.IFeeCalculator가 불리는ActionEvaluator에서는 체인에 접근할 수 없어 base fee 등을 계산하기 위한 정보를 넣어주기가 어렵습니다.또한,
IFeeCalculator를 통한 요금 징수 부분이ActionEvaluator안쪽에 구현되어 있어 다음과 같은 문제가 있습니다.GatherTransactionToPropose()단계에서 알 수가 없습니다.ActionEvaluator가 Action을 실행하는 것 이외에 다른 상태 전이를 암시적으로 일으킵니다.목표 및 제안
IFeeCalculator
목표
IFeeCalculator가 더 다양한 정보를 담고 있고, 이를IVariableFeeCalculator를 통해 블록 인덱스에 맞는IFeeCalculator를 호출하는 형태를 가집니다.제안
IFeeCalculator가 다음과 같은 인터페이스를 가집니다.IVariableFeeCalculator는 다음과 같은 인터페이스를 가집니다.IFeeCollector
목표
IFeeCollector는IFeeCalculator를 통해 얻어 진 FAV를 가지고 다음과 같은 일을 수행합니다.ActionEvaluation을 반환합니다.제안
IFeeCollector는 다음과 같은 인터페이스를 가집니다.Beta Was this translation helpful? Give feedback.
All reactions