Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject blocks which emit Qi UTXOs to inactive chains #2388

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,23 @@ func (v *BlockValidator) ValidateBody(block *types.WorkObject) error {
if hash := types.CalcUncleHash(block.Uncles()); hash != header.UncleHash() {
return fmt.Errorf("uncle root hash mismatch: have %x, want %x", hash, header.UncleHash())
}
if v.hc.ProcessingState() {
if hash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil)); hash != header.TxHash() {
return fmt.Errorf("transaction root hash mismatch: have %x, want %x", hash, header.TxHash())
if hash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil)); hash != header.TxHash() {
return fmt.Errorf("transaction root hash mismatch: have %x, want %x", hash, header.TxHash())
}
activeLocations := common.NewChainsAdded(v.hc.currentExpansionNumber)
for _, tx := range block.Transactions() {
if types.QiTxType == tx.Type() {
for _, txo := range tx.TxOut() {
found := false
for _, activeLoc := range activeLocations {
if common.IsInChainScope(txo.Address, activeLoc) {
found = true
}
}
if !found {
gameofpointers marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("Qi TXO emitted to an inactive chain")
}
}
}
}
// The header view should have the etxs populated
Expand Down
13 changes: 13 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,21 @@ func (pool *TxPool) addQiTxs(txs types.Transactions) []error {
if etxPLimit < params.ETXPLimitMin {
etxPLimit = params.ETXPLimitMin
}
activeLocations := common.NewChainsAdded(pool.chain.CurrentBlock().ExpansionNumber())
transactionsWithoutErrors := make([]*types.TxWithMinerFee, 0, len(txs))
for _, tx := range txs {
// Reject TX if it emits an output to an inactive chain
for _, txo := range tx.TxOut() {
found := false
for _, activeLoc := range activeLocations {
if common.IsInChainScope(txo.Address, activeLoc) {
found = true
}
}
if !found {
errs = append(errs, fmt.Errorf("Qi TXO emitted to an inactive chain"))
}
}

totalQitIn, err := ValidateQiTxInputs(tx, pool.chain, pool.db, currentBlock, pool.signer, pool.chainconfig.Location, *pool.chainconfig.ChainID)
if err != nil {
Expand Down
Loading