Skip to content

Commit

Permalink
[Enhancement] Reintroduce the MapStore interface and SimpleMap an…
Browse files Browse the repository at this point in the history
…d make the `Badger` a submodules (#33)
  • Loading branch information
h5law authored Jan 3, 2024
1 parent 883d100 commit 6778485
Show file tree
Hide file tree
Showing 46 changed files with 1,584 additions and 1,167 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ jobs:
skip-cache: true
only-new-issues: true

- name: Install gocovmerge
run: go install github.com/wadey/gocovmerge@latest

- name: Create coverage report and run tests
run: |
# Run each of the tests (excluding benchmarks) outputting the JSON
# to the test_results.json file for usage in later steps.
set -euo pipefail
go test -v -json -p 1 ./ -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic 2>&1 | tee -a test_results.json
go test -v -json -p 1 ./... -mod=readonly -race -coverprofile=coverage1.txt -covermode=atomic 2>&1 | tee test_results.json
go test -v -json -p 1 ./kvstore/badger/... -mod=readonly -race -coverprofile=coverage2.txt -covermode=atomic 2>&1 | tee -a test_results.json
# Combine coverage reports
gocovmerge coverage1.txt coverage2.txt > coverage.txt
- name: Sanitize test results
# We're utilizing `tee` above which can capture non-json stdout output
Expand Down
64 changes: 38 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
SHELL := /bin/bash

.SILENT:

#####################
Expand All @@ -15,66 +13,80 @@ help: ## Prints all the targets in all the Makefiles
list: ## List all make targets
@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort

#####################
### Documentation ###
#####################

## Ensure godoc is installed
.PHONY: check_godoc
.PHONY:
# Internal helper target - check if godoc is installed
check_godoc:
{ \
if ( ! ( command -v godoc >/dev/null )); then \
if ( ! ( command -v godoc >/dev/null )); then \
echo "Seems like you don't have godoc installed. Make sure you install it via 'go install golang.org/x/tools/cmd/godoc@latest' before continuing"; \
exit 1; \
fi; \
fi; \
}

#####################
### Documentation ###
#### Testing ####
#####################

.PHONY: go_docs
go_docs: check_godoc ## Generate documentation for the project
echo "Visit http://localhost:6060/pkg/github.com/pokt-network/smt/"
godoc -http=:6060
.PHONY: test_all
test_all: ## runs the test suite
go test -v -p 1 ./... -mod=readonly -race

.PHONY: test_badger
test_badger: ## runs the badger KVStore submodule's test suite
go test -v -p 1 ./kvstore/badger/... -mod=readonly -race


#####################
#### Testing ####
### go helpers ###
#####################
.PHONY: mod_tidy
mod_tidy: ## runs go mod tidy for all (sub)modules
go mod tidy
cd kvstore/simplemap && go mod tidy
cd kvstore/badger && go mod tidy

.PHONY: test_all
test_all: ## runs the test suite
go test -v -p 1 ./ -mod=readonly -race
.PHONY: go_docs
go_docs: check_godoc ## Generate documentation for the project
echo "Visit http://localhost:6060/pkg/github.com/pokt-network/smt/"
godoc -http=:6060

#####################
### Benchmark ###
#####################

.PHONY: benchmark_all
bechmark_all: ## runs all benchmarks
go test -benchmem -run=^$ -bench Benchmark ./benchmarks -timeout 0
benchmark_all: ## runs all benchmarks
go test -tags=benchmark -benchmem -run=^$ -bench Benchmark ./benchmarks -timeout 0

.PHONY: benchmark_smt
benchmark_smt: ## runs all benchmarks for the SMT
go test -benchmem -run=^$ -bench=BenchmarkSparseMerkleTrie ./benchmarks -timeout 0
go test -tags=benchmark -benchmem -run=^$ -bench=BenchmarkSparseMerkleTrie ./benchmarks -timeout 0

.PHONY: benchmark_smt_fill
benchmark_smt_fill: ## runs a benchmark on filling the SMT with different amounts of values
go test -benchmem -run=^$ -bench=BenchmarkSparseMerkleTrie_Fill ./benchmarks -timeout 0 -benchtime 10x
go test -tags=benchmark -benchmem -run=^$ -bench=BenchmarkSparseMerkleTrie_Fill ./benchmarks -timeout 0 -benchtime 10x

.PHONY: benchmark_smt_ops
benchmark_smt_ops: ## runs the benchmarks testing different operations on the SMT against different sized tries
go test -benchmem -run=^$ -bench='BenchmarkSparseMerkleTrie_(Update|Get|Prove|Delete)' ./benchmarks -timeout 0
go test -tags=benchmark -benchmem -run=^$ -bench='BenchmarkSparseMerkleTrie_(Update|Get|Prove|Delete)' ./benchmarks -timeout 0

.PHONY: benchmark_smst
benchmark_smst: ## runs all benchmarks for the SMST
go test -benchmem -run=^$ -bench=BenchmarkSparseMerkleSumTrie ./benchmarks -timeout 0
go test -tags=benchmark -benchmem -run=^$ -bench=BenchmarkSparseMerkleSumTrie ./benchmarks -timeout 0

.PHONY: benchmark_smst_fill
benchmark_smst_fill: ## runs a benchmark on filling the SMST with different amounts of values
go test -benchmem -run=^$ -bench=BenchmarkSparseMerkleSumTrie_Fill ./benchmarks -timeout 0 -benchtime 10x
go test -tags=benchmark -benchmem -run=^$ -bench=BenchmarkSparseMerkleSumTrie_Fill ./benchmarks -timeout 0 -benchtime 10x

.PHONY: benchmark_smst_ops
benchmark_smst_ops: ## runs the benchmarks testing different operations on the SMST against different sized tries
go test -benchmem -run=^$ -bench='BenchmarkSparseMerkleSumTrie_(Update|Get|Prove|Delete)' ./benchmarks -timeout 0
benchmark_smst_ops: ## runs the benchmarks test different operations on the SMST against different sized tries
go test -tags=benchmark -benchmem -run=^$ -bench='BenchmarkSparseMerkleSumTrie_(Update|Get|Prove|Delete)' ./benchmarks -timeout 0

.PHONY: bechmark_proof_sizes
benchmark_proof_sizes: ## runs the benchmarks testing the proof sizes for different sized tries
go test -v ./benchmarks -run ProofSizes
.PHONY: benchmark_proof_sizes
benchmark_proof_sizes: ## runs the benchmarks test the proof sizes for different sized tries
go test -tags=benchmark -v ./benchmarks -run ProofSizes
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ To run all tests (excluding benchmarks) run the following command:
make test_all
```

To test the `badger` submodule that provides a more fully featured key-value
store, run the following command:

```sh
make test_badger
```

## Benchmarks

To run the full suite of benchmarks simply run the following command:
Expand Down
11 changes: 5 additions & 6 deletions benchmarks/bench_leaf_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build benchmark

package smt

import (
Expand All @@ -9,13 +11,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/pokt-network/smt"
"github.com/pokt-network/smt/kvstore/simplemap"
)

func BenchmarkSMTLeafSizes_Fill(b *testing.B) {
trieSizes := []int{100000, 500000, 1000000, 5000000, 10000000} // number of leaves
leafSizes := []int{256, 512, 1024, 2048, 4096, 8192, 16384} // number of bytes per leaf
nodes, err := smt.NewKVStore("")
require.NoError(b, err)
nodes := simplemap.NewSimpleMap()
for _, trieSize := range trieSizes {
for _, leafSize := range leafSizes {
leaf := make([]byte, leafSize)
Expand All @@ -39,14 +41,12 @@ func BenchmarkSMTLeafSizes_Fill(b *testing.B) {
}
}
}
require.NoError(b, nodes.Stop())
}

func BenchmarkSMSTLeafSizes_Fill(b *testing.B) {
trieSizes := []int{100000, 500000, 1000000, 5000000, 10000000} // number of leaves
leafSizes := []int{256, 512, 1024, 2048, 4096, 8192, 16384} // number of bytes per leaf
nodes, err := smt.NewKVStore("")
require.NoError(b, err)
nodes := simplemap.NewSimpleMap()
for _, trieSize := range trieSizes {
for _, leafSize := range leafSizes {
leaf := make([]byte, leafSize)
Expand All @@ -70,5 +70,4 @@ func BenchmarkSMSTLeafSizes_Fill(b *testing.B) {
}
}
}
require.NoError(b, nodes.Stop())
}
Loading

0 comments on commit 6778485

Please sign in to comment.