-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
671 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of RskJ | ||
* Copyright (C) 2017 RSK Labs Ltd. | ||
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package co.rsk.logfilter; | ||
|
||
import org.ethereum.core.Bloom; | ||
|
||
/** | ||
* Created by ajlopez on 29/01/2019. | ||
*/ | ||
public class BlocksBloom { | ||
private final Bloom bloom = new Bloom(); | ||
private long fromBlock = -1; | ||
private long toBlock = -1; | ||
|
||
public Bloom getBloom() { return this.bloom; } | ||
|
||
public long fromBlock() { return this.fromBlock; } | ||
|
||
public long toBlock() { return this.toBlock; } | ||
|
||
public long size() { | ||
if (this.fromBlock == -1) { | ||
return 0; | ||
} | ||
|
||
return this.toBlock - this.fromBlock + 1; | ||
} | ||
|
||
public void addBlockBloom(long blockNumber, Bloom blockBloom) { | ||
if (fromBlock == -1) { | ||
fromBlock = blockNumber; | ||
toBlock = blockNumber; | ||
} | ||
else if (blockNumber == toBlock + 1) { | ||
toBlock = blockNumber; | ||
} | ||
else { | ||
throw new UnsupportedOperationException("Block out of sequence"); | ||
} | ||
|
||
this.bloom.or(blockBloom); | ||
} | ||
|
||
public boolean matches(Bloom bloom) { | ||
return this.bloom.matches(bloom); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
rskj-core/src/main/java/co/rsk/logfilter/BlocksBloomStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file is part of RskJ | ||
* Copyright (C) 2017 RSK Labs Ltd. | ||
* (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package co.rsk.logfilter; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* Created by ajlopez on 05/02/2019. | ||
*/ | ||
public class BlocksBloomStore { | ||
private final int noBlocks; | ||
private final int noConfirmations; | ||
private final Map<Long, BlocksBloom> blocksBloom = new ConcurrentHashMap<>(); | ||
|
||
public BlocksBloomStore(int noBlocks, int noConfirmations) { | ||
this.noBlocks = noBlocks; | ||
this.noConfirmations = noConfirmations; | ||
} | ||
|
||
public boolean hasBlockNumber(long blockNumber) { | ||
return this.blocksBloom.containsKey(this.firstNumberInRange(blockNumber)); | ||
} | ||
|
||
public BlocksBloom getBlocksBloomByNumber(long number) { | ||
return this.blocksBloom.get(firstNumberInRange(number)); | ||
} | ||
|
||
public void setBlocksBloom(BlocksBloom blocksBloom) { | ||
this.blocksBloom.put(blocksBloom.fromBlock(), blocksBloom); | ||
} | ||
|
||
public long firstNumberInRange(long number) { | ||
return number - (number % this.noBlocks); | ||
} | ||
|
||
public long lastNumberInRange(long number) { | ||
return firstNumberInRange(number) + this.noBlocks - 1; | ||
} | ||
|
||
public int getNoBlocks() { | ||
return this.noBlocks; | ||
} | ||
|
||
public int getNoConfirmations() { return this.noConfirmations; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,4 +312,4 @@ cache { | |
# precaution we'll set the limit to 100K entries. | ||
max-elements: 100000 | ||
} | ||
} | ||
} |
Oops, something went wrong.