Commit db74695e authored by Robin Owens's avatar Robin Owens Committed by Andreas Schildbach

LevelDb fully pruned block store.

parent 4d1ed917
/*
* 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 @@ ...@@ -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>
/*
* 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();
}
}
/*
* 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();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment