Skip to content

Commit

Permalink
interop: slightly rephrase BuildHFSpecificMD logic
Browse files Browse the repository at this point in the history
Technically, we can always buildHFSpecificMD() if contract is active, but we
just optimize the build out in some cases. switch slightly obfuscates this
and requires having the call in two branches.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Nov 23, 2024
1 parent d6c983b commit df5946d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/core/interop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,16 @@ func (c *ContractMD) BuildHFSpecificMD(activeIn *config.Hardfork) {
}

for _, hf := range append([]config.Hardfork{config.HFDefault}, config.Hardforks...) {
switch {
case hf.Cmp(start) < 0:
if hf.Cmp(start) < 0 {
continue
case hf.Cmp(start) == 0:
c.buildHFSpecificMD(hf)
default:
if _, ok := c.ActiveHFs[hf]; !ok {
// Intentionally omit HFSpecificContractMD structure copying since mdCache is read-only.
c.mdCache[hf] = c.mdCache[hf.Prev()]
continue
}
}
_, contractHasChanges := c.ActiveHFs[hf]
if hf.Cmp(start) == 0 || contractHasChanges {
c.buildHFSpecificMD(hf)
} else {
// Optimize out MD rebuild, the contract is the same.
// Intentionally omit HFSpecificContractMD structure copying since mdCache is read-only.
c.mdCache[hf] = c.mdCache[hf.Prev()]
}
}
}
Expand Down

0 comments on commit df5946d

Please sign in to comment.