Require only inputs not be prefilled (#1345)

* bug invalidateAndInsertPruningPoint: if ValidateAndInsertBlock returned a non-RuleError error - the error was ignored

* Convert checkNoPrefilledFields into checkNoPrefilledInputs

* Add log line

* clone pruning point when passing to validateBlockTransactionsAgainstPastUTXO
This commit is contained in:
Svarog 2021-01-04 15:55:08 +02:00 committed by GitHub
parent 778375c4af
commit 789a7379bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 25 deletions

View File

@ -36,14 +36,12 @@ func (bp *blockProcessor) validateAndInsertPruningPoint(newPruningPoint *externa
log.Infof("Inserting the new pruning point %s", newPruningPointHash)
_, err = bp.validateAndInsertBlock(newPruningPoint, true)
if err != nil {
if errors.As(err, &ruleerrors.RuleError{}) {
// This should never happen because we already validated the block with bp.validateBlockAndDiscardChanges.
// We use Errorf so it won't be identified later on to be a rule error and will eventually cause
// the program to panic.
return errors.Errorf("validateAndInsertBlock returned unexpected rule error while processing "+
"the pruning point: %+v", err)
}
if err != nil && errors.As(err, &ruleerrors.RuleError{}) {
// This should never happen because we already validated the block with bp.validateBlockAndDiscardChanges.
// We use Errorf so it won't be identified later on to be a rule error and will eventually cause
// the program to panic.
return errors.Errorf("validateAndInsertBlock returned unexpected rule error while processing "+
"the pruning point: %+v", err)
}
return nil
return err
}

View File

@ -23,7 +23,7 @@ func (v *blockValidator) ValidateBodyInIsolation(blockHash *externalapi.DomainHa
return err
}
err = v.checkNoPrefilledFields(block)
err = v.checkNoPrefilledInputs(block)
if err != nil {
return err
}
@ -230,20 +230,8 @@ func (v *blockValidator) checkBlockSize(block *externalapi.DomainBlock) error {
return nil
}
func (v *blockValidator) checkNoPrefilledFields(block *externalapi.DomainBlock) error {
func (v *blockValidator) checkNoPrefilledInputs(block *externalapi.DomainBlock) error {
for _, tx := range block.Transactions {
if tx.Fee != 0 {
return errors.Errorf("transaction %s has a prefilled fee", consensushashing.TransactionID(tx))
}
if tx.Mass != 0 {
return errors.Errorf("transaction %s has a prefilled mass", consensushashing.TransactionID(tx))
}
if tx.ID != nil {
return errors.Errorf("transaction %s has a prefilled ID", consensushashing.TransactionID(tx))
}
for i, input := range tx.Inputs {
if input.UTXOEntry != nil {
return errors.Errorf("input %d in transaction %s has a prefilled UTXO entry",

View File

@ -115,7 +115,9 @@ func (csm *consensusStateManager) applyMergeSetBlocks(blockHash *externalapi.Dom
log.Debugf("applyMergeSetBlocks start for block %s", blockHash)
defer log.Tracef("applyMergeSetBlocks end for block %s", blockHash)
mergeSetBlocks, err := csm.blockStore.Blocks(csm.databaseContext, ghostdagData.MergeSet())
mergeSetHashes := ghostdagData.MergeSet()
log.Debugf("Merge set for block %s is %v", blockHash, mergeSetHashes)
mergeSetBlocks, err := csm.blockStore.Blocks(csm.databaseContext, mergeSetHashes)
if err != nil {
return nil, nil, err
}

View File

@ -108,7 +108,11 @@ func (csm *consensusStateManager) updatePruningPoint(newPruningPoint *externalap
// Before we manually mark the new pruning point as valid, we validate that all of its transactions are valid
// against the provided UTXO set.
log.Debugf("Validating that the pruning point is UTXO valid")
err = csm.validateBlockTransactionsAgainstPastUTXO(newPruningPoint, utxo.NewUTXODiff())
// validateBlockTransactionsAgainstPastUTXO pre-fills the block's transactions inputs, which
// are assumed to not be pre-filled during further validations.
// Therefore - clone newPruningPoint before passing it to validateBlockTransactionsAgainstPastUTXO
err = csm.validateBlockTransactionsAgainstPastUTXO(newPruningPoint.Clone(), utxo.NewUTXODiff())
if err != nil {
return err
}