*: move NVB and Conflicts attributes out of extensions

They're a part of the regular protocol now.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-04-07 11:26:58 +03:00 committed by Roman Khimov
parent a59fd50844
commit f3c1283ac6
11 changed files with 109 additions and 152 deletions

View file

@ -356,7 +356,7 @@ protocol-related settings described in the table below.
| MemPoolSize | `int` | `50000` | Size of the node's memory pool where transactions are stored before they are added to block. | | MemPoolSize | `int` | `50000` | Size of the node's memory pool where transactions are stored before they are added to block. |
| NativeActivations | `map[string][]uint32` | ContractManagement: [0]<br>StdLib: [0]<br>CryptoLib: [0]<br>LedgerContract: [0]<br>NeoToken: [0]<br>GasToken: [0]<br>PolicyContract: [0]<br>RoleManagement: [0]<br>OracleContract: [0] | The list of histories of native contracts updates. Each list item shod be presented as a known native contract name with the corresponding list of chain's heights. The contract is not active until chain reaches the first height value specified in the list. | `Notary` is supported. | | NativeActivations | `map[string][]uint32` | ContractManagement: [0]<br>StdLib: [0]<br>CryptoLib: [0]<br>LedgerContract: [0]<br>NeoToken: [0]<br>GasToken: [0]<br>PolicyContract: [0]<br>RoleManagement: [0]<br>OracleContract: [0] | The list of histories of native contracts updates. Each list item shod be presented as a known native contract name with the corresponding list of chain's heights. The contract is not active until chain reaches the first height value specified in the list. | `Notary` is supported. |
| P2PNotaryRequestPayloadPoolSize | `int` | `1000` | Size of the node's P2P Notary request payloads memory pool where P2P Notary requests are stored before main or fallback transaction is completed and added to the chain.<br>This option is valid only if `P2PSigExtensions` are enabled. | Not supported by the C# node, thus may affect heterogeneous networks functionality. | | P2PNotaryRequestPayloadPoolSize | `int` | `1000` | Size of the node's P2P Notary request payloads memory pool where P2P Notary requests are stored before main or fallback transaction is completed and added to the chain.<br>This option is valid only if `P2PSigExtensions` are enabled. | Not supported by the C# node, thus may affect heterogeneous networks functionality. |
| P2PSigExtensions | `bool` | `false` | Enables following additional Notary service related logic:<br>• Transaction attributes `NotValidBefore`, `Conflicts` and `NotaryAssisted`<br>• Network payload of the `P2PNotaryRequest` type<br>• Native `Notary` contract<br>• Notary node module | Not supported by the C# node, thus may affect heterogeneous networks functionality. | | P2PSigExtensions | `bool` | `false` | Enables following additional Notary service related logic:<br>• Transaction attribute `NotaryAssisted`<br>• Network payload of the `P2PNotaryRequest` type<br>• Native `Notary` contract<br>• Notary node module | Not supported by the C# node, thus may affect heterogeneous networks functionality. |
| P2PStateExchangeExtensions | `bool` | `false` | Enables the following P2P MPT state data exchange logic: <br>`StateSyncInterval` protocol setting <br>• P2P commands `GetMPTDataCMD` and `MPTDataCMD` | Not supported by the C# node, thus may affect heterogeneous networks functionality. Can be supported either on MPT-complete node (`KeepOnlyLatestState`=`false`) or on light GC-enabled node (`RemoveUntraceableBlocks=true`) in which case `KeepOnlyLatestState` setting doesn't change the behavior, an appropriate set of MPTs is always stored (see `RemoveUntraceableBlocks`). | | P2PStateExchangeExtensions | `bool` | `false` | Enables the following P2P MPT state data exchange logic: <br>`StateSyncInterval` protocol setting <br>• P2P commands `GetMPTDataCMD` and `MPTDataCMD` | Not supported by the C# node, thus may affect heterogeneous networks functionality. Can be supported either on MPT-complete node (`KeepOnlyLatestState`=`false`) or on light GC-enabled node (`RemoveUntraceableBlocks=true`) in which case `KeepOnlyLatestState` setting doesn't change the behavior, an appropriate set of MPTs is always stored (see `RemoveUntraceableBlocks`). |
| RemoveUntraceableBlocks | `bool`| `false` | Denotes whether old blocks should be removed from cache and database. If enabled, then only the last `MaxTraceableBlocks` are stored and accessible to smart contracts. Old MPT data is also deleted in accordance with `GarbageCollectionPeriod` setting. If enabled along with `P2PStateExchangeExtensions`, then old blocks and MPT states will be removed up to the second latest state synchronisation point (see `StateSyncInterval`). | This setting is deprecated in favor of the same setting in the ApplicationConfiguration and will be removed in future node versions. If both settings are used, setting any of them to true enables the function. | | RemoveUntraceableBlocks | `bool`| `false` | Denotes whether old blocks should be removed from cache and database. If enabled, then only the last `MaxTraceableBlocks` are stored and accessible to smart contracts. Old MPT data is also deleted in accordance with `GarbageCollectionPeriod` setting. If enabled along with `P2PStateExchangeExtensions`, then old blocks and MPT states will be removed up to the second latest state synchronisation point (see `StateSyncInterval`). | This setting is deprecated in favor of the same setting in the ApplicationConfiguration and will be removed in future node versions. If both settings are used, setting any of them to true enables the function. |
| ReservedAttributes | `bool` | `false` | Allows to have reserved attributes range for experimental or private purposes. | | ReservedAttributes | `bool` | `false` | Allows to have reserved attributes range for experimental or private purposes. |

View file

@ -2573,9 +2573,6 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact
return fmt.Errorf("%w: oracle tx has insufficient gas", ErrInvalidAttribute) return fmt.Errorf("%w: oracle tx has insufficient gas", ErrInvalidAttribute)
} }
case transaction.NotValidBeforeT: case transaction.NotValidBeforeT:
if !bc.config.P2PSigExtensions {
return fmt.Errorf("%w: NotValidBefore attribute was found, but P2PSigExtensions are disabled", ErrInvalidAttribute)
}
nvb := tx.Attributes[i].Value.(*transaction.NotValidBefore).Height nvb := tx.Attributes[i].Value.(*transaction.NotValidBefore).Height
curHeight := bc.BlockHeight() curHeight := bc.BlockHeight()
if isPartialTx { if isPartialTx {
@ -2595,9 +2592,6 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact
} }
} }
case transaction.ConflictsT: case transaction.ConflictsT:
if !bc.config.P2PSigExtensions {
return fmt.Errorf("%w: Conflicts attribute was found, but P2PSigExtensions are disabled", ErrInvalidAttribute)
}
conflicts := tx.Attributes[i].Value.(*transaction.Conflicts) conflicts := tx.Attributes[i].Value.(*transaction.Conflicts)
// Only fully-qualified dao.ErrAlreadyExists error bothers us here, thus, we // Only fully-qualified dao.ErrAlreadyExists error bothers us here, thus, we
// can safely omit the payer argument to HasTransaction call to improve performance a bit. // can safely omit the payer argument to HasTransaction call to improve performance a bit.

View file

@ -1535,7 +1535,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
}} }}
return tx return tx
} }
t.Run("Disabled", func(t *testing.T) { t.Run("Disabled", func(t *testing.T) { // check that NVB attribute is not an extension anymore.
bcBad, validatorBad, committeeBad := chain.NewMultiWithCustomConfig(t, func(c *config.Blockchain) { bcBad, validatorBad, committeeBad := chain.NewMultiWithCustomConfig(t, func(c *config.Blockchain) {
c.P2PSigExtensions = false c.P2PSigExtensions = false
c.ReservedAttributes = false c.ReservedAttributes = false
@ -1543,8 +1543,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
eBad := neotest.NewExecutor(t, bcBad, validatorBad, committeeBad) eBad := neotest.NewExecutor(t, bcBad, validatorBad, committeeBad)
tx := getNVBTx(eBad, bcBad.BlockHeight()) tx := getNVBTx(eBad, bcBad.BlockHeight())
err := bcBad.VerifyTx(tx) err := bcBad.VerifyTx(tx)
require.Error(t, err) require.NoError(t, err)
require.True(t, strings.Contains(err.Error(), "invalid attribute: NotValidBefore attribute was found, but P2PSigExtensions are disabled"))
}) })
t.Run("Enabled", func(t *testing.T) { t.Run("Enabled", func(t *testing.T) {
t.Run("NotYetValid", func(t *testing.T) { t.Run("NotYetValid", func(t *testing.T) {
@ -1621,7 +1620,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
}} }}
return tx return tx
} }
t.Run("disabled", func(t *testing.T) { t.Run("disabled", func(t *testing.T) { // check that Conflicts attribute is not an extension anymore.
bcBad, validatorBad, committeeBad := chain.NewMultiWithCustomConfig(t, func(c *config.Blockchain) { bcBad, validatorBad, committeeBad := chain.NewMultiWithCustomConfig(t, func(c *config.Blockchain) {
c.P2PSigExtensions = false c.P2PSigExtensions = false
c.ReservedAttributes = false c.ReservedAttributes = false
@ -1629,8 +1628,7 @@ func TestBlockchain_VerifyTx(t *testing.T) {
eBad := neotest.NewExecutor(t, bcBad, validatorBad, committeeBad) eBad := neotest.NewExecutor(t, bcBad, validatorBad, committeeBad)
tx := getConflictsTx(eBad, util.Uint256{1, 2, 3}) tx := getConflictsTx(eBad, util.Uint256{1, 2, 3})
err := bcBad.VerifyTx(tx) err := bcBad.VerifyTx(tx)
require.Error(t, err) require.NoError(t, err)
require.True(t, strings.Contains(err.Error(), "invalid attribute: Conflicts attribute was found, but P2PSigExtensions are disabled"))
}) })
t.Run("enabled", func(t *testing.T) { t.Run("enabled", func(t *testing.T) {
t.Run("dummy on-chain conflict", func(t *testing.T) { t.Run("dummy on-chain conflict", func(t *testing.T) {

View file

@ -766,14 +766,12 @@ func (dao *Simple) DeleteBlock(h util.Uint256) error {
for _, tx := range b.Transactions { for _, tx := range b.Transactions {
copy(key[1:], tx.Hash().BytesBE()) copy(key[1:], tx.Hash().BytesBE())
dao.Store.Delete(key) dao.Store.Delete(key)
if dao.Version.P2PSigExtensions {
for _, attr := range tx.GetAttributes(transaction.ConflictsT) { for _, attr := range tx.GetAttributes(transaction.ConflictsT) {
hash := attr.Value.(*transaction.Conflicts).Hash hash := attr.Value.(*transaction.Conflicts).Hash
copy(key[1:], hash.BytesBE()) copy(key[1:], hash.BytesBE())
dao.Store.Delete(key) dao.Store.Delete(key)
} }
} }
}
return nil return nil
} }
@ -830,7 +828,7 @@ func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32,
return buf.Err return buf.Err
} }
dao.Store.Put(key, buf.Bytes()) dao.Store.Put(key, buf.Bytes())
if dao.Version.P2PSigExtensions {
var ( var (
valuePrefix []byte valuePrefix []byte
newSigners []byte newSigners []byte
@ -876,7 +874,6 @@ func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32,
newSigners = slice.Copy(val[newSignersOffset:]) newSigners = slice.Copy(val[newSignersOffset:])
} }
} }
}
return nil return nil
} }

View file

@ -11,5 +11,4 @@ type Feer interface {
FeePerByte() int64 FeePerByte() int64
GetUtilityTokenBalance(util.Uint160) *big.Int GetUtilityTokenBalance(util.Uint160) *big.Int
BlockHeight() uint32 BlockHeight() uint32
P2PSigExtensionsEnabled() bool
} }

View file

@ -145,7 +145,6 @@ func (mp *Pool) HasConflicts(t *transaction.Transaction, fee Feer) bool {
if mp.containsKey(t.Hash()) { if mp.containsKey(t.Hash()) {
return true return true
} }
if fee.P2PSigExtensionsEnabled() {
// do not check sender's signature and fee // do not check sender's signature and fee
if _, ok := mp.conflicts[t.Hash()]; ok { if _, ok := mp.conflicts[t.Hash()]; ok {
return true return true
@ -155,7 +154,6 @@ func (mp *Pool) HasConflicts(t *transaction.Transaction, fee Feer) bool {
return true return true
} }
} }
}
return false return false
} }
@ -229,12 +227,10 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error {
mp.oracleResp[id] = t.Hash() mp.oracleResp[id] = t.Hash()
} }
if fee.P2PSigExtensionsEnabled() {
// Remove conflicting transactions. // Remove conflicting transactions.
for _, conflictingTx := range conflictsToBeRemoved { for _, conflictingTx := range conflictsToBeRemoved {
mp.removeInternal(conflictingTx.Hash(), fee) mp.removeInternal(conflictingTx.Hash(), fee)
} }
}
// Insert into a sorted array (from max to min, that could also be done // Insert into a sorted array (from max to min, that could also be done
// using sort.Sort(sort.Reverse()), but it incurs more overhead. Notice // using sort.Sort(sort.Reverse()), but it incurs more overhead. Notice
// also that we're searching for a position that is strictly more // also that we're searching for a position that is strictly more
@ -255,9 +251,7 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error {
// Ditch the last one. // Ditch the last one.
unlucky := mp.verifiedTxes[len(mp.verifiedTxes)-1] unlucky := mp.verifiedTxes[len(mp.verifiedTxes)-1]
delete(mp.verifiedMap, unlucky.txn.Hash()) delete(mp.verifiedMap, unlucky.txn.Hash())
if fee.P2PSigExtensionsEnabled() {
mp.removeConflictsOf(unlucky.txn) mp.removeConflictsOf(unlucky.txn)
}
if attrs := unlucky.txn.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 { if attrs := unlucky.txn.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 {
delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID) delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID)
} }
@ -277,13 +271,11 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error {
mp.verifiedTxes[n] = pItem mp.verifiedTxes[n] = pItem
} }
mp.verifiedMap[t.Hash()] = t mp.verifiedMap[t.Hash()] = t
if fee.P2PSigExtensionsEnabled() {
// Add conflicting hashes to the mp.conflicts list. // Add conflicting hashes to the mp.conflicts list.
for _, attr := range t.GetAttributes(transaction.ConflictsT) { for _, attr := range t.GetAttributes(transaction.ConflictsT) {
hash := attr.Value.(*transaction.Conflicts).Hash hash := attr.Value.(*transaction.Conflicts).Hash
mp.conflicts[hash] = append(mp.conflicts[hash], t.Hash()) mp.conflicts[hash] = append(mp.conflicts[hash], t.Hash())
} }
}
// we already checked balance in checkTxConflicts, so don't need to check again // we already checked balance in checkTxConflicts, so don't need to check again
mp.tryAddSendersFee(pItem.txn, fee, false) mp.tryAddSendersFee(pItem.txn, fee, false)
@ -330,10 +322,8 @@ func (mp *Pool) removeInternal(hash util.Uint256, feer Feer) {
senderFee := mp.fees[payer] senderFee := mp.fees[payer]
senderFee.feeSum.SubUint64(&senderFee.feeSum, uint64(tx.SystemFee+tx.NetworkFee)) senderFee.feeSum.SubUint64(&senderFee.feeSum, uint64(tx.SystemFee+tx.NetworkFee))
mp.fees[payer] = senderFee mp.fees[payer] = senderFee
if feer.P2PSigExtensionsEnabled() {
// remove all conflicting hashes from mp.conflicts list // remove all conflicting hashes from mp.conflicts list
mp.removeConflictsOf(tx) mp.removeConflictsOf(tx)
}
if attrs := tx.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 { if attrs := tx.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 {
delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID) delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID)
} }
@ -360,9 +350,7 @@ func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool, feer Feer)
// because items are iterated one-by-one in increasing order. // because items are iterated one-by-one in increasing order.
newVerifiedTxes := mp.verifiedTxes[:0] newVerifiedTxes := mp.verifiedTxes[:0]
mp.fees = make(map[util.Uint160]utilityBalanceAndFees) // it'd be nice to reuse existing map, but we can't easily clear it mp.fees = make(map[util.Uint160]utilityBalanceAndFees) // it'd be nice to reuse existing map, but we can't easily clear it
if feer.P2PSigExtensionsEnabled() {
mp.conflicts = make(map[util.Uint256][]util.Uint256) mp.conflicts = make(map[util.Uint256][]util.Uint256)
}
height := feer.BlockHeight() height := feer.BlockHeight()
var ( var (
staleItems []item staleItems []item
@ -370,12 +358,10 @@ func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool, feer Feer)
for _, itm := range mp.verifiedTxes { for _, itm := range mp.verifiedTxes {
if isOK(itm.txn) && mp.checkPolicy(itm.txn, policyChanged) && mp.tryAddSendersFee(itm.txn, feer, true) { if isOK(itm.txn) && mp.checkPolicy(itm.txn, policyChanged) && mp.tryAddSendersFee(itm.txn, feer, true) {
newVerifiedTxes = append(newVerifiedTxes, itm) newVerifiedTxes = append(newVerifiedTxes, itm)
if feer.P2PSigExtensionsEnabled() {
for _, attr := range itm.txn.GetAttributes(transaction.ConflictsT) { for _, attr := range itm.txn.GetAttributes(transaction.ConflictsT) {
hash := attr.Value.(*transaction.Conflicts).Hash hash := attr.Value.(*transaction.Conflicts).Hash
mp.conflicts[hash] = append(mp.conflicts[hash], itm.txn.Hash()) mp.conflicts[hash] = append(mp.conflicts[hash], itm.txn.Hash())
} }
}
if mp.resendThreshold != 0 { if mp.resendThreshold != 0 {
// item is resent at resendThreshold, 2*resendThreshold, 4*resendThreshold ... // item is resent at resendThreshold, 2*resendThreshold, 4*resendThreshold ...
// so quotient must be a power of two. // so quotient must be a power of two.
@ -524,7 +510,6 @@ func (mp *Pool) checkTxConflicts(tx *transaction.Transaction, fee Feer) ([]*tran
conflictsToBeRemoved []*transaction.Transaction conflictsToBeRemoved []*transaction.Transaction
conflictingFee int64 conflictingFee int64
) )
if fee.P2PSigExtensionsEnabled() {
// Step 1: check if `tx` was in attributes of mempooled transactions. // Step 1: check if `tx` was in attributes of mempooled transactions.
if conflictingHashes, ok := mp.conflicts[tx.Hash()]; ok { if conflictingHashes, ok := mp.conflicts[tx.Hash()]; ok {
for _, hash := range conflictingHashes { for _, hash := range conflictingHashes {
@ -572,9 +557,6 @@ func (mp *Pool) checkTxConflicts(tx *transaction.Transaction, fee Feer) ([]*tran
expectedSenderFee.feeSum.SubUint64(&expectedSenderFee.feeSum, uint64(conflictingTx.SystemFee+conflictingTx.NetworkFee)) expectedSenderFee.feeSum.SubUint64(&expectedSenderFee.feeSum, uint64(conflictingTx.SystemFee+conflictingTx.NetworkFee))
} }
} }
} else {
expectedSenderFee = actualSenderFee
}
_, err := checkBalance(tx, expectedSenderFee) _, err := checkBalance(tx, expectedSenderFee)
return conflictsToBeRemoved, err return conflictsToBeRemoved, err
} }

View file

@ -40,10 +40,6 @@ func (fs *FeerStub) GetUtilityTokenBalance(uint160 util.Uint160) *big.Int {
return big.NewInt(fs.balance) return big.NewInt(fs.balance)
} }
func (fs *FeerStub) P2PSigExtensionsEnabled() bool {
return fs.p2pSigExt
}
func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) { func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) {
mp := New(10, 0, false, nil) mp := New(10, 0, false, nil)
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0) tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)

View file

@ -26,11 +26,6 @@ func (f NotaryFeer) BlockHeight() uint32 {
return f.bc.BlockHeight() return f.bc.BlockHeight()
} }
// P2PSigExtensionsEnabled implements mempool.Feer interface.
func (f NotaryFeer) P2PSigExtensionsEnabled() bool {
return f.bc.P2PSigExtensionsEnabled()
}
// NewNotaryFeer returns new NotaryFeer instance. // NewNotaryFeer returns new NotaryFeer instance.
func NewNotaryFeer(bc Ledger) NotaryFeer { func NewNotaryFeer(bc Ledger) NotaryFeer {
return NotaryFeer{ return NotaryFeer{

View file

@ -1001,7 +1001,6 @@ type feerStub struct {
func (f feerStub) FeePerByte() int64 { return 1 } func (f feerStub) FeePerByte() int64 { return 1 }
func (f feerStub) GetUtilityTokenBalance(util.Uint160) *big.Int { return big.NewInt(100000000) } func (f feerStub) GetUtilityTokenBalance(util.Uint160) *big.Int { return big.NewInt(100000000) }
func (f feerStub) BlockHeight() uint32 { return f.blockHeight } func (f feerStub) BlockHeight() uint32 { return f.blockHeight }
func (f feerStub) P2PSigExtensionsEnabled() bool { return false }
func (f feerStub) GetBaseExecFee() int64 { return interop.DefaultBaseExecFee } func (f feerStub) GetBaseExecFee() int64 { return interop.DefaultBaseExecFee }
func TestMemPool(t *testing.T) { func TestMemPool(t *testing.T) {

View file

@ -98,6 +98,7 @@ type (
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
HeaderHeight() uint32 HeaderHeight() uint32
InitVerificationContext(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error InitVerificationContext(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error
P2PSigExtensionsEnabled() bool
SubscribeForBlocks(ch chan *block.Block) SubscribeForBlocks(ch chan *block.Block)
SubscribeForExecutions(ch chan *state.AppExecResult) SubscribeForExecutions(ch chan *state.AppExecResult)
SubscribeForNotifications(ch chan *state.ContainedNotificationEvent) SubscribeForNotifications(ch chan *state.ContainedNotificationEvent)

View file

@ -173,10 +173,6 @@ func (fs *FeerStub) GetUtilityTokenBalance(acc util.Uint160) *big.Int {
return big.NewInt(1000000 * native.GASFactor) return big.NewInt(1000000 * native.GASFactor)
} }
func (fs FeerStub) P2PSigExtensionsEnabled() bool {
return false
}
func (fs FeerStub) GetBaseExecFee() int64 { func (fs FeerStub) GetBaseExecFee() int64 {
return interop.DefaultBaseExecFee return interop.DefaultBaseExecFee
} }