mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
consensus/misc: eip-1559 comment
This commit is contained in:
parent
ae9eae457c
commit
409be2442a
4 changed files with 25 additions and 4 deletions
|
|
@ -31,8 +31,10 @@ import (
|
|||
// VerifyEIP1559Header verifies some header attributes which were changed in EIP-1559,
|
||||
// - gas limit check
|
||||
// - basefee check
|
||||
// VerifyEIP1559Header 함수는 EIP-1559이후 변경된 헤더 속성을 검증한다
|
||||
func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Header) error {
|
||||
// Verify that the gas limit remains within allowed bounds
|
||||
// gas limit이 허용된 범위 안에 있는지 검증한다
|
||||
parentGasLimit := parent.GasLimit
|
||||
if !config.IsLondon(parent.Number) {
|
||||
parentGasLimit = parent.GasLimit * config.ElasticityMultiplier()
|
||||
|
|
@ -41,10 +43,12 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
|
|||
return err
|
||||
}
|
||||
// Verify the header is not malformed
|
||||
// 헤더가 잘못된 형식이 아닌지 확인한다(baseFee)
|
||||
if header.BaseFee == nil {
|
||||
return errors.New("header is missing baseFee")
|
||||
}
|
||||
// Verify the baseFee is correct based on the parent header.
|
||||
// baseFee가 parent header에 근거해 올바른지 확인한다.
|
||||
expectedBaseFee := CalcBaseFee(config, parent)
|
||||
if header.BaseFee.Cmp(expectedBaseFee) != 0 {
|
||||
return fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d",
|
||||
|
|
@ -54,14 +58,18 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
|
|||
}
|
||||
|
||||
// CalcBaseFee calculates the basefee of the header.
|
||||
// CalcBaseFee는 header의 basefee를 계산한다.
|
||||
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
||||
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
|
||||
// 현재 블록이 EIP-1559의 첫번째 블록이면, InitialBaseFee를 반환한다.
|
||||
// -----런던인지 검사하는데 첫번째 블록과 어떤 관련성 있는지?
|
||||
if !config.IsLondon(parent.Number) {
|
||||
return new(big.Int).SetUint64(params.InitialBaseFee)
|
||||
}
|
||||
|
||||
parentGasTarget := parent.GasLimit / config.ElasticityMultiplier()
|
||||
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
|
||||
// 부모블록의 gasUsed가 target과 같으면, baseFee는 변경되지 않음.
|
||||
if parent.GasUsed == parentGasTarget {
|
||||
return new(big.Int).Set(parent.BaseFee)
|
||||
}
|
||||
|
|
@ -74,6 +82,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
|||
if parent.GasUsed > parentGasTarget {
|
||||
// If the parent block used more gas than its target, the baseFee should increase.
|
||||
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
|
||||
// 만약 부모 블록이 타겟보다 많은 gas를 사용했으면, baseFee는 증가한다.
|
||||
num.SetUint64(parent.GasUsed - parentGasTarget)
|
||||
num.Mul(num, parent.BaseFee)
|
||||
num.Div(num, denom.SetUint64(parentGasTarget))
|
||||
|
|
@ -84,12 +93,13 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
|||
} else {
|
||||
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
|
||||
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
|
||||
// 만약 부모 블록이 타겟보다 적은 gas를 사용했으면, baseFee는 감소한다.
|
||||
num.SetUint64(parentGasTarget - parent.GasUsed)
|
||||
num.Mul(num, parent.BaseFee)
|
||||
num.Div(num, denom.SetUint64(parentGasTarget))
|
||||
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
|
||||
baseFee := num.Sub(parent.BaseFee, num)
|
||||
|
||||
// 코드가 위 로직이랑 일관되지 않은데 개선사항?
|
||||
return math.BigMax(baseFee, common.Big0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,10 @@ import (
|
|||
|
||||
// VerifyGaslimit verifies the header gas limit according increase/decrease
|
||||
// in relation to the parent gas limit.
|
||||
// VerifyGaslimit은 header gas limit관 parentgas limit의 증가/감소관계를 확인한다.
|
||||
func VerifyGaslimit(parentGasLimit, headerGasLimit uint64) error {
|
||||
// Verify that the gas limit remains within allowed bounds
|
||||
// gas limit이 허용된 범위안에 있는지 확인한다
|
||||
diff := int64(parentGasLimit) - int64(headerGasLimit)
|
||||
if diff < 0 {
|
||||
diff *= -1
|
||||
|
|
|
|||
|
|
@ -319,12 +319,16 @@ var NetworkNames = map[string]string{
|
|||
}
|
||||
|
||||
// ChainConfig is the core config which determines the blockchain settings.
|
||||
// ChainConfig는 블록체인 설정을 결정하는 핵심 config이다.
|
||||
//
|
||||
// ChainConfig is stored in the database on a per block basis. This means
|
||||
// that any network, identified by its genesis block, can have its own
|
||||
// set of configuration options.
|
||||
// ChainConfig는 블록 단위로 데이터베이스에 저장된다.
|
||||
// 이는 제네시스 블록에 의해 구별되는 모든 네트워크는 고유의 configuration option set를 가질 수 있음을 의미한다.
|
||||
type ChainConfig struct {
|
||||
ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection
|
||||
// chainId는 현재 체인을 식별하고 replay attack의 protection에 사용된다
|
||||
|
||||
HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead)
|
||||
|
||||
|
|
@ -539,6 +543,7 @@ func (c *ChainConfig) IsBerlin(num *big.Int) bool {
|
|||
}
|
||||
|
||||
// IsLondon returns whether num is either equal to the London fork block or greater.
|
||||
// IsLondon는 num이 London fork block보다 크거나 같은지 여부를 반환한다.
|
||||
func (c *ChainConfig) IsLondon(num *big.Int) bool {
|
||||
return isBlockForked(c.LondonBlock, num)
|
||||
}
|
||||
|
|
@ -746,11 +751,13 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
|
|||
}
|
||||
|
||||
// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.
|
||||
// BaseFeeChangeDenominator는 블록간 base fee가 변할 수 있는 양을 제한한다.
|
||||
func (c *ChainConfig) BaseFeeChangeDenominator() uint64 {
|
||||
return DefaultBaseFeeChangeDenominator
|
||||
}
|
||||
|
||||
// ElasticityMultiplier bounds the maximum gas limit an EIP-1559 block may have.
|
||||
// ElasticityMultiplier는 EIP-1559 블록이 가지는 최대 gas limit을 제한한다
|
||||
func (c *ChainConfig) ElasticityMultiplier() uint64 {
|
||||
return DefaultElasticityMultiplier
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,7 +125,9 @@ const (
|
|||
CreateBySelfdestructGas uint64 = 25000
|
||||
|
||||
DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
|
||||
// 블록 간 변화하는 base fee 양 제한
|
||||
DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
|
||||
// EIP-1559블록의 최대 gas limit 범위
|
||||
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.
|
||||
|
||||
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
|
||||
|
|
|
|||
Loading…
Reference in a new issue