Skip to content

Commit

Permalink
fix bip30Enable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fffreedom committed Sep 25, 2018
1 parent 9e19216 commit 28d3d6b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
21 changes: 11 additions & 10 deletions logic/lchain/lchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ func ConnectBlock(pblock *block.Block, pindex *blockindex.BlockIndex, view *utxo
// applied to all blocks except the two in the chain that violate it. This
// prevents exploiting the issue against nodes during their initial block
// download.
zHash := util.HashZero
fEnforceBIP30 := (!blockHash.IsEqual(&zHash)) ||
!((pindex.Height == 91842 &&
blockHash.IsEqual(util.HashFromString("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec"))) ||
(pindex.Height == 91880 &&
blockHash.IsEqual(util.HashFromString("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721"))))
//zHash := util.HashZero
//fEnforceBIP30 := (!blockHash.IsEqual(&zHash)) ||
// !((pindex.Height == 91842 &&
// blockHash.IsEqual(util.HashFromString("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec"))) ||
// (pindex.Height == 91880 &&
// blockHash.IsEqual(util.HashFromString("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721"))))
bip30Enable := !((pindex.Height == 91842 && blockHash.IsEqual(util.HashFromString("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec"))) ||
(pindex.Height == 91880 && blockHash.IsEqual(util.HashFromString("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721"))))

// Once BIP34 activated it was not possible to create new duplicate
// coinBases and thus other than starting with the 2 existing duplicate
Expand All @@ -135,9 +137,8 @@ func ConnectBlock(pblock *block.Block, pindex *blockindex.BlockIndex, view *utxo
pindexBIP34height := pindex.Prev.GetAncestor(params.BIP34Height)
// Only continue to enforce if we're below BIP34 activation height or the
// block hash at that height doesn't correspond.
BIP34Hash := params.BIP34Hash
bip34 := pindexBIP34height == nil || !(pindexBIP34height != nil && pindexBIP34height.GetBlockHash().IsEqual(&BIP34Hash))
fEnforceBIP30 = fEnforceBIP30 && bip34
bip34Enable := pindexBIP34height != nil && pindexBIP34height.GetBlockHash().IsEqual(&params.BIP34Hash)
bip30Enable = bip30Enable && !bip34Enable

flags := lblock.GetBlockScriptFlags(pindex.Prev)
blockSubSidy := lblock.GetBlockSubsidy(pindex.Height, params)
Expand All @@ -146,7 +147,7 @@ func ConnectBlock(pblock *block.Block, pindex *blockindex.BlockIndex, view *utxo
log.Print("bench", "debug", " - Fork checks: %.2fms [%.2fs]",
0.001*float64(nTime2-nTime1), float64(gPersist.GlobalTimeForks)*0.000001)

var coinsMap, blockUndo, err = ltx.ApplyBlockTransactions(pblock.Txs, fEnforceBIP30, flags,
var coinsMap, blockUndo, err = ltx.ApplyBlockTransactions(pblock.Txs, bip30Enable, flags,
fScriptChecks, blockSubSidy, pindex.Height, consensus.GetMaxBlockSigOpsCount(uint64(pblock.EncodeSize())))
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions model/utxo/coinsmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func (cm *CoinsMap) AddCoin(point *outpoint.OutPoint, coin *Coin, possibleOverwr
return
}

if !possibleOverwrite {
oldcoin := cm.FetchCoin(point)
if oldcoin != nil {
panic("Adding new coin that is in coincache or db")
}
}
//if !possibleOverwrite {
// oldcoin := cm.FetchCoin(point)
// if oldcoin != nil {
// panic("Adding new coin that is in coincache or db")
// }
//}
coin.dirty = false
coin.fresh = true
cm.cacheCoins[*point] = coin
Expand Down
2 changes: 2 additions & 0 deletions persist/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

"github.com/copernet/copernicus/log"
lvldb "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/comparer"
"github.com/syndtr/goleveldb/leveldb/filter"
Expand Down Expand Up @@ -213,6 +214,7 @@ func (dbw *DBWrapper) Read(key []byte) ([]byte, error) {
value, err = dbw.db.Get(key, &dbw.readOption)
}
if err != nil {
log.Debug("Read DB key: %s err: %v", key, err)
return nil, err
}
xor(value, dbw.obfuscateKey)
Expand Down
9 changes: 9 additions & 0 deletions util/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,12 @@ func TestSipHash(t *testing.T) {
(uint64(i+6) << 48) | (uint64(i+7) << 56))
}
}

func TestHash_IsEqual(t *testing.T) {
hash1 := HashFromString("00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")
hash2 := HashFromString("00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")
if !hash1.IsEqual(hash2) {
t.Errorf("IsEqual test failed")
return
}
}

0 comments on commit 28d3d6b

Please sign in to comment.