Skip to content

Commit 94af395

Browse files
committed
native: store TimePerBlock setting inside native Policy
A part of #3745. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
1 parent 24a6d84 commit 94af395

22 files changed

Lines changed: 160 additions & 42 deletions

‎docs/node-configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ in development and can change in an incompatible way.
480480
| `Basilisk` | Enables strict smart contract script check against a set of JMP instructions and against method boundaries enabled on contract deploy or update. Increases `stackitem.Integer` JSON parsing precision up to the maximum value supported by the NeoVM. Enables strict check for notifications emitted by a contract to precisely match the events specified in the contract manifest. | https://github.com/nspcc-dev/neo-go/pull/3056 <br> https://github.com/neo-project/neo/pull/2881 <br> https://github.com/nspcc-dev/neo-go/pull/3080 <br> https://github.com/neo-project/neo/pull/2883 <br> https://github.com/nspcc-dev/neo-go/pull/3085 <br> https://github.com/neo-project/neo/pull/2810 |
481481
| `Cockatrice` | Introduces the ability to update native contracts. Includes a couple of new native smart contract APIs: `keccak256` of native CryptoLib contract and `getCommitteeAddress` of native NeoToken contract. | https://github.com/nspcc-dev/neo-go/pull/3402 <br> https://github.com/neo-project/neo/pull/2942 <br> https://github.com/nspcc-dev/neo-go/pull/3301 <br> https://github.com/neo-project/neo/pull/2925 <br> https://github.com/nspcc-dev/neo-go/pull/3362 <br> https://github.com/neo-project/neo/pull/3154 |
482482
| `Domovoi` | Makes node use executing contract state for the contract call permissions check instead of the state stored in the native Management contract. In C# also makes System.Runtime.GetNotifications interop properly count stack references of notification parameters which prevents users from creating objects that exceed MaxStackSize constraint, but NeoGo has never had this bug, thus proper behaviour is preserved even before HFDomovoi. It results in the fact that some T5 testnet transactions have different ApplicationLogs compared to the C# node, but the node states match. | https://github.com/nspcc-dev/neo-go/pull/3476 <br> https://github.com/neo-project/neo/pull/3290 <br> https://github.com/nspcc-dev/neo-go/pull/3473 <br> https://github.com/neo-project/neo/pull/3290 <br> https://github.com/neo-project/neo/pull/3301 <br> https://github.com/nspcc-dev/neo-go/pull/3485 |
483-
| `Echidna` | Introduces `Designation` event extension with `Old` and `New` roles data to native RoleManagement contract. Adds support for `base64UrlEncode` and `base64UrlDecode` methods to native StdLib contract. Extends the list of required call flags for `registerCandidate`, `unregisterCandidate`and `vote` methods of native NeoToken contract with AllowNotify flag. Enables `onNEP17Payment` method of NEO contract for candidate registration. Introduces constraint for maximum number of execution notifications. | https://github.com/nspcc-dev/neo-go/pull/3554 <br> https://github.com/nspcc-dev/neo-go/pull/3761 <br> https://github.com/nspcc-dev/neo-go/pull/3554 <br> https://github.com/neo-project/neo/pull/3597 <br> https://github.com/nspcc-dev/neo-go/pull/3700 <br> https://github.com/nspcc-dev/neo-go/pull/3640 <br> https://github.com/neo-project/neo/pull/3548 |
483+
| `Echidna` | Introduces `Designation` event extension with `Old` and `New` roles data to native RoleManagement contract. Adds support for `base64UrlEncode` and `base64UrlDecode` methods to native StdLib contract. Extends the list of required call flags for `registerCandidate`, `unregisterCandidate`and `vote` methods of native NeoToken contract with AllowNotify flag. Enables `onNEP17Payment` method of NEO contract for candidate registration. Introduces constraint for maximum number of execution notifications. Introduces `setMSPerBlock` and `getMSPerBlock` methods of native Policy contract. | https://github.com/nspcc-dev/neo-go/pull/3554 <br> https://github.com/nspcc-dev/neo-go/pull/3761 <br> https://github.com/nspcc-dev/neo-go/pull/3554 <br> https://github.com/neo-project/neo/pull/3597 <br> https://github.com/nspcc-dev/neo-go/pull/3700 <br> https://github.com/nspcc-dev/neo-go/pull/3640 <br> https://github.com/neo-project/neo/pull/3548 <br> https://github.com/neo-project/neo/pull/3622 <br> https://github.com/nspcc-dev/neo-go/pull/3835 |
484484

485485

486486
## DB compatibility

‎pkg/config/genesis_extensions.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"encoding/base64"
55
"fmt"
6+
"time"
67

78
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
89
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
@@ -19,6 +20,12 @@ type Genesis struct {
1920
// genesis block. It is NeoGo extension and must be disabled on the public
2021
// Neo N3 networks.
2122
Transaction *GenesisTransaction
23+
// DefaultTimePerBlock is the time interval between blocks that consensus
24+
// nodes work with. It must be an integer number of milliseconds. It differs
25+
// from Protocol level configuration in that this value is used starting
26+
// from HFEchidna to initialize MSPerBlock value of native Policy
27+
// contract.
28+
DefaultTimePerBlock time.Duration
2229
}
2330

2431
// GenesisTransaction is a placeholder for script that should be included into genesis

‎pkg/config/hardfork.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const (
4545
HFDomovoi // Domovoi
4646
// HFEchidna represents hard-fork introduced in #3554 (ported from
4747
// https://github.com/neo-project/neo/pull/3454), #3640 (ported from
48-
// https://github.com/neo-project/neo/pull/3548).
48+
// https://github.com/neo-project/neo/pull/3548), #3835 (ported from
49+
// https://github.com/neo-project/neo/pull/3622).
4950
HFEchidna // Echidna
5051
// hfLast denotes the end of hardforks enum. Consider adding new hardforks
5152
// before hfLast.

‎pkg/config/protocol_config.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ type (
6262
// It is valid only if P2PStateExchangeExtensions are enabled.
6363
StateSyncInterval int `yaml:"StateSyncInterval"`
6464
// TimePerBlock is the time interval between blocks that consensus nodes work with.
65-
// It must be an integer number of milliseconds.
65+
// It must be an integer number of milliseconds. This value is applicable till
66+
// HFEchidna; use Genesis-level configuration to set up further block acceptance
67+
// interval.
6668
TimePerBlock time.Duration `yaml:"TimePerBlock"`
6769
ValidatorsCount uint32 `yaml:"ValidatorsCount"`
6870
// Validators stores history of changes to consensus node number (height: number).

‎pkg/core/blockchain.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ func NewBlockchain(s storage.Store, cfg config.Blockchain, log *zap.Logger) (*Bl
293293
log.Info("TimePerBlock is not set or wrong, using default value",
294294
zap.Duration("TimePerBlock", cfg.TimePerBlock))
295295
}
296+
if cfg.Genesis.DefaultTimePerBlock <= 0 {
297+
cfg.Genesis.DefaultTimePerBlock = defaultTimePerBlock
298+
log.Info("Genesis DefaultTimePerBlock is not set or wrong, using default value",
299+
zap.Duration("DefaultTimePerBlock", cfg.Genesis.DefaultTimePerBlock))
300+
}
296301
if cfg.MaxValidUntilBlockIncrement == 0 {
297302
const timePerDay = 24 * time.Hour
298303

@@ -1109,7 +1114,7 @@ func (bc *Blockchain) initializeNativeCache(blockHeight uint32, d *dao.Simple) e
11091114
if !bc.isHardforkEnabled(c.ActiveIn(), blockHeight) {
11101115
continue
11111116
}
1112-
err := c.InitializeCache(blockHeight, d)
1117+
err := c.InitializeCache(bc.isHardforkEnabled, blockHeight, d)
11131118
if err != nil {
11141119
return fmt.Errorf("failed to initialize cache for %s: %w", c.Metadata().Name, err)
11151120
}

‎pkg/core/interop/context.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,17 @@ type Contract interface {
190190
// been deployed, but in-memory cached data were lost due to the node reset.
191191
// It should be called each time after node restart iff the contract was
192192
// deployed and no Initialize method was called.
193-
InitializeCache(blockHeight uint32, d *dao.Simple) error
193+
InitializeCache(isHardforkEnabled IsHardforkEnabled, blockHeight uint32, d *dao.Simple) error
194194
// Metadata returns generic native contract metadata.
195195
Metadata() *ContractMD
196196
OnPersist(*Context) error
197197
PostPersist(*Context) error
198198
}
199199

200+
// IsHardforkEnabled is a delegate denoting whether specific hardfork is enabled
201+
// at the given height.
202+
type IsHardforkEnabled func(hf *config.Hardfork, blockHeight uint32) bool
203+
200204
// ContractMD represents a generic hardfork-independent native contract instance.
201205
type ContractMD struct {
202206
ID int32

‎pkg/core/native/crypto.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (c *Crypto) Initialize(ic *interop.Context, hf *config.Hardfork, newMD *int
341341
}
342342

343343
// InitializeCache implements the Contract interface.
344-
func (c *Crypto) InitializeCache(blockHeight uint32, d *dao.Simple) error {
344+
func (c *Crypto) InitializeCache(_ interop.IsHardforkEnabled, blockHeight uint32, d *dao.Simple) error {
345345
return nil
346346
}
347347

‎pkg/core/native/designate.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (s *Designate) Initialize(ic *interop.Context, hf *config.Hardfork, newMD *
163163

164164
// InitializeCache fills native Designate cache from DAO. It is called at non-zero height, thus
165165
// we can fetch the roles data right from the storage.
166-
func (s *Designate) InitializeCache(blockHeight uint32, d *dao.Simple) error {
166+
func (s *Designate) InitializeCache(_ interop.IsHardforkEnabled, blockHeight uint32, d *dao.Simple) error {
167167
cache := &DesignationCache{}
168168
roles := []noderoles.Role{noderoles.Oracle, noderoles.NeoFSAlphabet, noderoles.StateValidator, noderoles.P2PNotary}
169169
for _, r := range roles {

‎pkg/core/native/ledger.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (l *Ledger) Initialize(ic *interop.Context, hf *config.Hardfork, newMD *int
8686
}
8787

8888
// InitializeCache implements the Contract interface.
89-
func (l *Ledger) InitializeCache(blockHeight uint32, d *dao.Simple) error {
89+
func (l *Ledger) InitializeCache(_ interop.IsHardforkEnabled, blockHeight uint32, d *dao.Simple) error {
9090
return nil
9191
}
9292

‎pkg/core/native/management.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ func (m *Management) OnPersist(ic *interop.Context) error {
704704
// InitializeCache initializes contract cache with the proper values from storage.
705705
// Cache initialization should be done apart from Initialize because Initialize is
706706
// called only when deploying native contracts.
707-
func (m *Management) InitializeCache(blockHeight uint32, d *dao.Simple) error {
707+
func (m *Management) InitializeCache(_ interop.IsHardforkEnabled, blockHeight uint32, d *dao.Simple) error {
708708
cache := &ManagementCache{
709709
contracts: make(map[util.Uint160]*state.Contract),
710710
nep11: make(map[util.Uint160]struct{}),

0 commit comments

Comments
 (0)