Merge pull request #1963 from nspcc-dev/custom-mvubi

config: make `MaxValidUntilBlockIncrement` configurable
This commit is contained in:
Roman Khimov 2021-05-17 15:18:38 +03:00 committed by GitHub
commit f0e603c4e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 10 deletions

View file

@ -26,6 +26,10 @@ type (
MaxTraceableBlocks uint32 `yaml:"MaxTraceableBlocks"` MaxTraceableBlocks uint32 `yaml:"MaxTraceableBlocks"`
// MaxTransactionsPerBlock is the maximum amount of transactions per block. // MaxTransactionsPerBlock is the maximum amount of transactions per block.
MaxTransactionsPerBlock uint16 `yaml:"MaxTransactionsPerBlock"` 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 is the list of histories of native contracts updates.
NativeUpdateHistories map[string][]uint32 `yaml:"NativeActivations"` NativeUpdateHistories map[string][]uint32 `yaml:"NativeActivations"`
// P2PSigExtensions enables additional signature-related logic. // P2PSigExtensions enables additional signature-related logic.

View file

@ -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", log.Info("MaxTransactionsPerBlock is not set or wrong, using default value",
zap.Uint16("MaxTransactionsPerBlock", cfg.MaxTransactionsPerBlock)) 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) committee, err := committeeFromConfig(cfg)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1426,7 +1433,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
height := bc.BlockHeight() height := bc.BlockHeight()
isPartialTx := data != nil 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) return fmt.Errorf("%w: ValidUntilBlock = %d, current height = %d", ErrTxExpired, t.ValidUntilBlock, height)
} }
// Policying. // Policying.

View file

@ -210,7 +210,7 @@ func TestCreateBasicChain(t *testing.T) {
// Prepare some transaction for future submission. // Prepare some transaction for future submission.
txSendRaw := newNEP17Transfer(bc.contracts.NEO.Hash, priv0ScriptHash, priv1.GetScriptHash(), int64(fixedn.Fixed8FromInt64(1000))) 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.Nonce = 0x1234
txSendRaw.Signers = []transaction.Signer{{ txSendRaw.Signers = []transaction.Signer{{
Account: priv0ScriptHash, Account: priv0ScriptHash,

View file

@ -392,8 +392,9 @@ func (n *Notary) GetMaxNotValidBeforeDelta(dao dao.DAO) uint32 {
// setMaxNotValidBeforeDelta is Notary contract method and sets the maximum NotValidBefore delta. // setMaxNotValidBeforeDelta is Notary contract method and sets the maximum NotValidBefore delta.
func (n *Notary) setMaxNotValidBeforeDelta(ic *interop.Context, args []stackitem.Item) stackitem.Item { func (n *Notary) setMaxNotValidBeforeDelta(ic *interop.Context, args []stackitem.Item) stackitem.Item {
value := toUint32(args[0]) value := toUint32(args[0])
if value > transaction.MaxValidUntilBlockIncrement/2 || value < uint32(ic.Chain.GetConfig().ValidatorsCount) { maxInc := ic.Chain.GetConfig().MaxValidUntilBlockIncrement
panic(fmt.Errorf("MaxNotValidBeforeDelta cannot be more than %d or less than %d", transaction.MaxValidUntilBlockIncrement/2, ic.Chain.GetConfig().ValidatorsCount)) 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) { if !n.NEO.checkCommittee(ic) {
panic("invalid committee signature") panic("invalid committee signature")

View file

@ -326,5 +326,5 @@ func TestMaxNotValidBeforeDelta(t *testing.T) {
chain := newTestChain(t) chain := newTestChain(t)
testGetSet(t, chain, chain.contracts.Notary.Hash, "MaxNotValidBeforeDelta", 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))
} }

View file

@ -19,10 +19,6 @@ const (
// MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is // MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is
// set to be 102400. // set to be 102400.
MaxTransactionSize = 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 // MaxAttributes is maximum number of attributes including signers that can be contained
// within a transaction. It is set to be 16. // within a transaction. It is set to be 16.
MaxAttributes = 16 MaxAttributes = 16

View file

@ -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) { func (o *Oracle) CreateResponseTx(gasForResponse int64, height uint32, resp *transaction.OracleResponse) (*transaction.Transaction, error) {
tx := transaction.New(o.oracleResponse, 0) tx := transaction.New(o.oracleResponse, 0)
tx.Nonce = uint32(resp.ID) tx.Nonce = uint32(resp.ID)
tx.ValidUntilBlock = height + transaction.MaxValidUntilBlockIncrement tx.ValidUntilBlock = height + o.Chain.GetConfig().MaxValidUntilBlockIncrement
tx.Attributes = []transaction.Attribute{{ tx.Attributes = []transaction.Attribute{{
Type: transaction.OracleResponseT, Type: transaction.OracleResponseT,
Value: resp, Value: resp,