mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
les: add an event emission to the les bloombits test
This commit is contained in:
parent
390d54c3e0
commit
4b567839b6
3 changed files with 36 additions and 25 deletions
|
|
@ -1124,10 +1124,8 @@ func (pm *ProtocolManager) getHelperTrie(id uint, idx uint64) (common.Hash, stri
|
||||||
|
|
||||||
// getHelperTrieAuxData returns requested auxiliary data for the given HelperTrie request
|
// getHelperTrieAuxData returns requested auxiliary data for the given HelperTrie request
|
||||||
func (pm *ProtocolManager) getHelperTrieAuxData(req HelperTrieReq) []byte {
|
func (pm *ProtocolManager) getHelperTrieAuxData(req HelperTrieReq) []byte {
|
||||||
if req.Type == htCanonical && req.AuxReq == auxHeader {
|
switch {
|
||||||
if len(req.Key) != 8 {
|
case req.Type == htCanonical && req.AuxReq == auxHeader && len(req.Key) == 8:
|
||||||
return nil
|
|
||||||
}
|
|
||||||
blockNum := binary.BigEndian.Uint64(req.Key)
|
blockNum := binary.BigEndian.Uint64(req.Key)
|
||||||
hash := core.GetCanonicalHash(pm.chainDb, blockNum)
|
hash := core.GetCanonicalHash(pm.chainDb, blockNum)
|
||||||
return core.GetHeaderRLP(pm.chainDb, hash, blockNum)
|
return core.GetHeaderRLP(pm.chainDb, hash, blockNum)
|
||||||
|
|
|
||||||
|
|
@ -472,7 +472,7 @@ func TestGetBloombitsProofs(t *testing.T) {
|
||||||
// Assemble the test environment
|
// Assemble the test environment
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
pm := newTestProtocolManagerMust(t, false, light.BloomTrieFrequency+256, testChainGen, nil, nil, db)
|
pm := newTestProtocolManagerMust(t, false, light.BloomTrieFrequency+256, testChainGen, nil, nil, db)
|
||||||
//bc := pm.blockchain.(*core.BlockChain)
|
bc := pm.blockchain.(*core.BlockChain)
|
||||||
peer, _ := newTestPeer(t, "peer", 2, pm, true)
|
peer, _ := newTestPeer(t, "peer", 2, pm, true)
|
||||||
defer peer.close()
|
defer peer.close()
|
||||||
|
|
||||||
|
|
@ -480,12 +480,13 @@ func TestGetBloombitsProofs(t *testing.T) {
|
||||||
time.Sleep(100 * time.Millisecond * time.Duration(light.BloomTrieFrequency/4096)) // Chain indexer throttling
|
time.Sleep(100 * time.Millisecond * time.Duration(light.BloomTrieFrequency/4096)) // Chain indexer throttling
|
||||||
time.Sleep(250 * time.Millisecond) // CI tester slack
|
time.Sleep(250 * time.Millisecond) // CI tester slack
|
||||||
|
|
||||||
|
// Request and verify each bit of the bloom bits proofs
|
||||||
|
for bit := 0; bit < 2048; bit++ {
|
||||||
// Assemble therequest and proofs for the bloombits
|
// Assemble therequest and proofs for the bloombits
|
||||||
bit := rand.Intn(2048)
|
|
||||||
key := make([]byte, 10)
|
key := make([]byte, 10)
|
||||||
|
|
||||||
binary.BigEndian.PutUint16(key[:2], uint16(bit))
|
binary.BigEndian.PutUint16(key[:2], uint16(bit))
|
||||||
binary.BigEndian.PutUint64(key[2:], 0)
|
binary.BigEndian.PutUint64(key[2:], uint64(light.BloomTrieFrequency))
|
||||||
|
|
||||||
requests := []HelperTrieReq{{
|
requests := []HelperTrieReq{{
|
||||||
Type: htBloomBits,
|
Type: htBloomBits,
|
||||||
|
|
@ -494,11 +495,16 @@ func TestGetBloombitsProofs(t *testing.T) {
|
||||||
}}
|
}}
|
||||||
var proofs HelperTrieResps
|
var proofs HelperTrieResps
|
||||||
|
|
||||||
|
root := light.GetBloomTrieRoot(db, 0, bc.GetHeaderByNumber(light.BloomTrieFrequency-1).Hash())
|
||||||
|
trie, _ := trie.New(root, trie.NewDatabase(ethdb.NewTable(db, light.BloomTrieTablePrefix)))
|
||||||
|
trie.Prove(key, 0, &proofs.Proofs)
|
||||||
|
|
||||||
// Send the proof request and verify the response
|
// Send the proof request and verify the response
|
||||||
cost := peer.GetRequestCost(GetHelperTrieProofsMsg, len(requests))
|
cost := peer.GetRequestCost(GetHelperTrieProofsMsg, len(requests))
|
||||||
sendRequest(peer.app, GetHelperTrieProofsMsg, 42, cost, requests)
|
sendRequest(peer.app, GetHelperTrieProofsMsg, 42, cost, requests)
|
||||||
if err := expectResponse(peer.app, HelperTrieProofsMsg, 42, testBufLimit, proofs); err != nil {
|
if err := expectResponse(peer.app, HelperTrieProofsMsg, 42, testBufLimit, proofs); err != nil {
|
||||||
t.Errorf("proofs mismatch: %v", err)
|
t.Errorf("bit %d: proofs mismatch: %v", bit, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,9 @@ var (
|
||||||
testContractCodeDeployed = testContractCode[16:]
|
testContractCodeDeployed = testContractCode[16:]
|
||||||
testContractDeployed = uint64(2)
|
testContractDeployed = uint64(2)
|
||||||
|
|
||||||
|
testEventEmitterCode = common.Hex2Bytes("60606040523415600e57600080fd5b7f57050ab73f6b9ebdd9f76b8d4997793f48cf956e965ee070551b9ca0bb71584e60405160405180910390a160358060476000396000f3006060604052600080fd00a165627a7a723058203f727efcad8b5811f8cb1fc2620ce5e8c63570d697aef968172de296ea3994140029")
|
||||||
|
testEventEmitterAddr common.Address
|
||||||
|
|
||||||
testBufLimit = uint64(100)
|
testBufLimit = uint64(100)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -86,15 +89,19 @@ func testChainGen(i int, block *core.BlockGen) {
|
||||||
// In block 2, the test bank sends some more ether to account #1.
|
// In block 2, the test bank sends some more ether to account #1.
|
||||||
// acc1Addr passes it on to account #2.
|
// acc1Addr passes it on to account #2.
|
||||||
// acc1Addr creates a test contract.
|
// acc1Addr creates a test contract.
|
||||||
tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, testBankKey)
|
// acc1Addr creates a test event.
|
||||||
nonce := block.TxNonce(acc1Addr)
|
nonce := block.TxNonce(acc1Addr)
|
||||||
|
|
||||||
|
tx1, _ := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, testBankKey)
|
||||||
tx2, _ := types.SignTx(types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, acc1Key)
|
tx2, _ := types.SignTx(types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil), signer, acc1Key)
|
||||||
nonce++
|
tx3, _ := types.SignTx(types.NewContractCreation(nonce+1, big.NewInt(0), 200000, big.NewInt(0), testContractCode), signer, acc1Key)
|
||||||
tx3, _ := types.SignTx(types.NewContractCreation(nonce, big.NewInt(0), 200000, big.NewInt(0), testContractCode), signer, acc1Key)
|
testContractAddr = crypto.CreateAddress(acc1Addr, nonce+1)
|
||||||
testContractAddr = crypto.CreateAddress(acc1Addr, nonce)
|
tx4, _ := types.SignTx(types.NewContractCreation(nonce+2, big.NewInt(0), 200000, big.NewInt(0), testEventEmitterCode), signer, acc1Key)
|
||||||
|
testEventEmitterAddr = crypto.CreateAddress(acc1Addr, nonce+2)
|
||||||
block.AddTx(tx1)
|
block.AddTx(tx1)
|
||||||
block.AddTx(tx2)
|
block.AddTx(tx2)
|
||||||
block.AddTx(tx3)
|
block.AddTx(tx3)
|
||||||
|
block.AddTx(tx4)
|
||||||
case 2:
|
case 2:
|
||||||
// Block 3 is empty but was mined by account #2.
|
// Block 3 is empty but was mined by account #2.
|
||||||
block.SetCoinbase(acc2Addr)
|
block.SetCoinbase(acc2Addr)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue