Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Reintroduce the MapStore interface and SimpleMap and make the Badger a submodules #33

Merged
merged 33 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb08623
feat: move benchmarks into docs folder, tidy readme and docs
h5law Dec 23, 2023
89dee09
feat: update gitignore
h5law Dec 23, 2023
dedc8f3
feat: cleanup and update workflow file
h5law Dec 23, 2023
2d215eb
feat: make codecov reports informational only
h5law Dec 23, 2023
63a9c3a
feat: add badger as a submodule
h5law Dec 22, 2023
83a994a
chore: makefile changes
h5law Dec 22, 2023
bcc569f
chore: update workflow to cover submodule tests
h5law Dec 22, 2023
4280986
chore: revert go version to 1.20.12
h5law Dec 23, 2023
0ce48aa
chore: unexport simpleMap MapStore implementation
h5law Dec 23, 2023
27dd854
chore: add kvstore package godoc
h5law Dec 23, 2023
66beac1
chore: s/badger/v4/g
h5law Dec 23, 2023
a0ebc3f
chore: use custom errors and wrap badgerv4 errors
h5law Dec 23, 2023
719ea55
squash: merged feat/doc-changes
h5law Jan 3, 2024
7a0f8fb
chore: add executable code examples
h5law Jan 3, 2024
17ccf68
feat: move interface out of submodule declarations and add simplemap …
h5law Jan 3, 2024
e4670f1
chore: better submodule support
h5law Jan 3, 2024
4518387
chore: grammar
h5law Jan 3, 2024
afeb02e
chore: fix example tests
h5law Jan 3, 2024
a64495a
s/name/desc/g
h5law Jan 3, 2024
f88a178
chore: clarify godoc
h5law Jan 3, 2024
81ff1b8
chore: refactor to use simplemap submodules
h5law Jan 3, 2024
e9892b1
chore: fix tests to cover simplemap submodule
h5law Jan 3, 2024
2d70eb0
chore: update godocs
h5law Jan 3, 2024
71ec219
feat: add SMT specific errors
h5law Jan 3, 2024
9bcd021
chore: add simplestore MapStore complaiance check
h5law Jan 3, 2024
f927cf2
chore: address comments
h5law Jan 3, 2024
6850a8a
chore: interface commennts
h5law Jan 3, 2024
fee3061
chore: s/name/desc/g
h5law Jan 3, 2024
a7c793c
chore: address comments
h5law Jan 3, 2024
9b1371c
chore: indentation
h5law Jan 3, 2024
27461f3
Merge branch 'main' into feat/badger-submodule
h5law Jan 3, 2024
538dcb5
chore: add simple to simplemap description
h5law Jan 3, 2024
58cc541
chore: address final comments
h5law Jan 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; \
}
h5law marked this conversation as resolved.
Show resolved Hide resolved

#####################
### 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 ###
#####################
h5law marked this conversation as resolved.
Show resolved Hide resolved

.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
Loading