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.
-
(영어 이후에 한국어가 따라옵니다.)
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 inIAction
as an argument, making it necessary to manage base fees separately if desired.IFeeCalculator
would alter the results of previous blocks.IFeeCalculator
being an interface forces unnecessary implementation of unused classes.IFeeCalculator
asActionEvaluator
callingIFeeCalculator
cannot access the chain.Moreover, the fee collection through
IFeeCalculator
is implemented insideActionEvaluator
, resulting in the following problems:GatherTransactionToPropose()
stage.ActionEvaluator
implicitly causes state transitions other than executing actions.Goals and Proposal
IFeeCalculator
Goals
IFeeCalculator
contains more diverse information, and is called throughIVariableFeeCalculator
to select the properIFeeCalculator
for the block index.Proposal
IFeeCalculator
has the following interface.IVariableFeeCalculator
has the following interface.IFeeCollector
Goals
IFeeCollector
verifies whether fees can be collected throughIFeeCalculator
-derived FAV, and performs the following actions:ActionEvaluation
.Proposal
IFeeCollector
has the following interface.Conclusion
This proposal suggests a refactoring of the current
IFeeCalculator
andIFeeCollector
interfaces 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