mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
LevelDb fully pruned block store.
This commit is contained in:
parent
4d1ed91737
commit
db74695e43
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 Robin Owens
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.bitcoinj.core;
|
||||||
|
|
||||||
|
import org.bitcoinj.store.BlockStoreException;
|
||||||
|
import org.bitcoinj.store.FullPrunedBlockStore;
|
||||||
|
import org.bitcoinj.store.H2FullPrunedBlockStore;
|
||||||
|
import org.bitcoinj.store.LevelDbFullPrunedBlockStore;
|
||||||
|
import org.junit.After;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An H2 implementation of the FullPrunedBlockStoreTest
|
||||||
|
*/
|
||||||
|
public class LevelDbFullPrunedBlockChainTest extends
|
||||||
|
AbstractFullPrunedBlockChainTest {
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
deleteFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FullPrunedBlockStore createStore(NetworkParameters params,
|
||||||
|
int blockCount) throws BlockStoreException {
|
||||||
|
deleteFiles();
|
||||||
|
return new LevelDbFullPrunedBlockStore(params, "test-leveldb",
|
||||||
|
blockCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteFiles() {
|
||||||
|
File f = new File("test-leveldb");
|
||||||
|
if (f != null && f.exists()) {
|
||||||
|
for (File c : f.listFiles())
|
||||||
|
c.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetStore(FullPrunedBlockStore store)
|
||||||
|
throws BlockStoreException {
|
||||||
|
((LevelDbFullPrunedBlockStore) store).resetStore();
|
||||||
|
}
|
||||||
|
}
|
@ -46,5 +46,11 @@
|
|||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>1.3.167</version>
|
<version>1.3.167</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.fusesource.leveldbjni</groupId>
|
||||||
|
<artifactId>leveldbjni-all</artifactId>
|
||||||
|
<version>1.8</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
48
examples/src/main/java/org/bitcoinj/examples/LevelDb.java
Normal file
48
examples/src/main/java/org/bitcoinj/examples/LevelDb.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 Robin Owens
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.bitcoinj.examples;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import org.bitcoinj.core.FullPrunedBlockChain;
|
||||||
|
import org.bitcoinj.core.PeerGroup;
|
||||||
|
import org.bitcoinj.params.MainNetParams;
|
||||||
|
import org.bitcoinj.store.FullPrunedBlockStore;
|
||||||
|
import org.bitcoinj.store.LevelDbFullPrunedBlockStore;
|
||||||
|
|
||||||
|
public class LevelDb {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
/*
|
||||||
|
* This is just a test runner that will download blockchain till block
|
||||||
|
* 390000 then exit.
|
||||||
|
*/
|
||||||
|
FullPrunedBlockStore store = new LevelDbFullPrunedBlockStore(
|
||||||
|
MainNetParams.get(), args[0], 1000, 100 * 1024 * 1024l,
|
||||||
|
10 * 1024 * 1024, 100000, true, 390000);
|
||||||
|
|
||||||
|
FullPrunedBlockChain vChain = new FullPrunedBlockChain(
|
||||||
|
MainNetParams.get(), store);
|
||||||
|
vChain.setRunScripts(false);
|
||||||
|
|
||||||
|
PeerGroup vPeerGroup = new PeerGroup(MainNetParams.get(), vChain);
|
||||||
|
vPeerGroup.setUseLocalhostPeerWhenPossible(true);
|
||||||
|
vPeerGroup.addAddress(InetAddress.getLocalHost());
|
||||||
|
|
||||||
|
vPeerGroup.start();
|
||||||
|
vPeerGroup.downloadBlockChain();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 Robin Owens
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.bitcoinj.examples;
|
||||||
|
|
||||||
|
import static org.fusesource.leveldbjni.JniDBFactory.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.iq80.leveldb.DB;
|
||||||
|
import org.iq80.leveldb.Options;
|
||||||
|
import org.iq80.leveldb.Range;
|
||||||
|
|
||||||
|
public class LevelDbSizes {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
DB db = null;
|
||||||
|
Options options = new Options();
|
||||||
|
options.createIfMissing(false);
|
||||||
|
try {
|
||||||
|
db = factory.open(new File(args[0]), options);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Thread.sleep(100000);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
byte[] from = new byte[1];
|
||||||
|
from[0] = (byte) i;
|
||||||
|
byte[] to = new byte[1];
|
||||||
|
to[0] = (byte) (i + 1);
|
||||||
|
|
||||||
|
long[] sizes = db.getApproximateSizes(new Range(from, to));
|
||||||
|
System.out.println("From:" + i + " to:" + (i + 1) + " Size: "
|
||||||
|
+ sizes[0]);
|
||||||
|
}
|
||||||
|
byte[] from = new byte[1];
|
||||||
|
from[0] = 0;
|
||||||
|
byte[] to = new byte[1];
|
||||||
|
to[0] = -128;
|
||||||
|
|
||||||
|
long[] sizes = db.getApproximateSizes(new Range(from, to));
|
||||||
|
System.out.println("Size: " + sizes[0]);
|
||||||
|
String stats = db.getProperty("leveldb.stats");
|
||||||
|
System.out.println(stats);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user