mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 23:25:22 +00:00
Merge pull request #1963 from nspcc-dev/custom-mvubi
config: make `MaxValidUntilBlockIncrement` configurable
This commit is contained in:
commit
f0e603c4e8
7 changed files with 18 additions and 10 deletions
|
@ -26,6 +26,10 @@ type (
|
|||
MaxTraceableBlocks uint32 `yaml:"MaxTraceableBlocks"`
|
||||
// MaxTransactionsPerBlock is the maximum amount of transactions per block.
|
||||
MaxTransactionsPerBlock uint16 `yaml:"MaxTransactionsPerBlock"`
|
||||
// MaxValidUntilBlockIncrement is the upper increment size of blockchain height in blocks
|
||||
// exceeding that a transaction should fail validation. It is set to estimated daily number
|
||||
// of blocks with 15s interval.
|
||||
MaxValidUntilBlockIncrement uint32 `yaml:"MaxValidUntilBlockIncrement"`
|
||||
// NativeUpdateHistories is the list of histories of native contracts updates.
|
||||
NativeUpdateHistories map[string][]uint32 `yaml:"NativeActivations"`
|
||||
// P2PSigExtensions enables additional signature-related logic.
|
||||
|
|
|
@ -190,6 +190,13 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
|
|||
log.Info("MaxTransactionsPerBlock is not set or wrong, using default value",
|
||||
zap.Uint16("MaxTransactionsPerBlock", cfg.MaxTransactionsPerBlock))
|
||||
}
|
||||
if cfg.MaxValidUntilBlockIncrement == 0 {
|
||||
const secondsPerDay = int(24 * time.Hour / time.Second)
|
||||
|
||||
cfg.MaxValidUntilBlockIncrement = uint32(secondsPerDay / cfg.SecondsPerBlock)
|
||||
log.Info("MaxValidUntilBlockIncrement is not set or wrong, using default value",
|
||||
zap.Uint32("MaxValidUntilBlockIncrement", cfg.MaxValidUntilBlockIncrement))
|
||||
}
|
||||
committee, err := committeeFromConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1426,7 +1433,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
|
|||
|
||||
height := bc.BlockHeight()
|
||||
isPartialTx := data != nil
|
||||
if t.ValidUntilBlock <= height || !isPartialTx && t.ValidUntilBlock > height+transaction.MaxValidUntilBlockIncrement {
|
||||
if t.ValidUntilBlock <= height || !isPartialTx && t.ValidUntilBlock > height+bc.config.MaxValidUntilBlockIncrement {
|
||||
return fmt.Errorf("%w: ValidUntilBlock = %d, current height = %d", ErrTxExpired, t.ValidUntilBlock, height)
|
||||
}
|
||||
// Policying.
|
||||
|
|
|
@ -210,7 +210,7 @@ func TestCreateBasicChain(t *testing.T) {
|
|||
|
||||
// Prepare some transaction for future submission.
|
||||
txSendRaw := newNEP17Transfer(bc.contracts.NEO.Hash, priv0ScriptHash, priv1.GetScriptHash(), int64(fixedn.Fixed8FromInt64(1000)))
|
||||
txSendRaw.ValidUntilBlock = transaction.MaxValidUntilBlockIncrement
|
||||
txSendRaw.ValidUntilBlock = bc.config.MaxValidUntilBlockIncrement
|
||||
txSendRaw.Nonce = 0x1234
|
||||
txSendRaw.Signers = []transaction.Signer{{
|
||||
Account: priv0ScriptHash,
|
||||
|
|
|
@ -392,8 +392,9 @@ func (n *Notary) GetMaxNotValidBeforeDelta(dao dao.DAO) uint32 {
|
|||
// setMaxNotValidBeforeDelta is Notary contract method and sets the maximum NotValidBefore delta.
|
||||
func (n *Notary) setMaxNotValidBeforeDelta(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||
value := toUint32(args[0])
|
||||
if value > transaction.MaxValidUntilBlockIncrement/2 || value < uint32(ic.Chain.GetConfig().ValidatorsCount) {
|
||||
panic(fmt.Errorf("MaxNotValidBeforeDelta cannot be more than %d or less than %d", transaction.MaxValidUntilBlockIncrement/2, ic.Chain.GetConfig().ValidatorsCount))
|
||||
maxInc := ic.Chain.GetConfig().MaxValidUntilBlockIncrement
|
||||
if value > maxInc/2 || value < uint32(ic.Chain.GetConfig().ValidatorsCount) {
|
||||
panic(fmt.Errorf("MaxNotValidBeforeDelta cannot be more than %d or less than %d", maxInc/2, ic.Chain.GetConfig().ValidatorsCount))
|
||||
}
|
||||
if !n.NEO.checkCommittee(ic) {
|
||||
panic("invalid committee signature")
|
||||
|
|
|
@ -326,5 +326,5 @@ func TestMaxNotValidBeforeDelta(t *testing.T) {
|
|||
chain := newTestChain(t)
|
||||
|
||||
testGetSet(t, chain, chain.contracts.Notary.Hash, "MaxNotValidBeforeDelta",
|
||||
140, int64(chain.GetConfig().ValidatorsCount), transaction.MaxValidUntilBlockIncrement/2)
|
||||
140, int64(chain.GetConfig().ValidatorsCount), int64(chain.config.MaxValidUntilBlockIncrement/2))
|
||||
}
|
||||
|
|
|
@ -19,10 +19,6 @@ const (
|
|||
// MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is
|
||||
// set to be 102400.
|
||||
MaxTransactionSize = 102400
|
||||
// MaxValidUntilBlockIncrement is the upper increment size of blockhain height in blocks
|
||||
// exceeding that a transaction should fail validation. It is set to estimated daily number
|
||||
// of blocks with 15s interval.
|
||||
MaxValidUntilBlockIncrement = 5760
|
||||
// MaxAttributes is maximum number of attributes including signers that can be contained
|
||||
// within a transaction. It is set to be 16.
|
||||
MaxAttributes = 16
|
||||
|
|
|
@ -84,7 +84,7 @@ func readResponse(rc gio.ReadCloser, limit int) ([]byte, error) {
|
|||
func (o *Oracle) CreateResponseTx(gasForResponse int64, height uint32, resp *transaction.OracleResponse) (*transaction.Transaction, error) {
|
||||
tx := transaction.New(o.oracleResponse, 0)
|
||||
tx.Nonce = uint32(resp.ID)
|
||||
tx.ValidUntilBlock = height + transaction.MaxValidUntilBlockIncrement
|
||||
tx.ValidUntilBlock = height + o.Chain.GetConfig().MaxValidUntilBlockIncrement
|
||||
tx.Attributes = []transaction.Attribute{{
|
||||
Type: transaction.OracleResponseT,
|
||||
Value: resp,
|
||||
|
|
Loading…
Reference in a new issue