Skip to content

Commit

Permalink
Squashed 'heminetwork/' changes from b3993a073..88047e707
Browse files Browse the repository at this point in the history
88047e707 Add tbcd, a small bitcoin daemon that participates on bitcoin p2p (ethereum-optimism#50)
1146a08b5 localnet reorg fix (ethereum-optimism#76)
87f18a191 build(deps): bump github.com/docker/docker (ethereum-optimism#64)
9073baeaf localnet (ethereum-optimism#37)
1588cbf04 Add common user-specific files to gitignore (ethereum-optimism#51)
210aabe7a Update popm.go, fix typo (ethereum-optimism#40)
a5e689493 make: automate copyright headers (ethereum-optimism#31)
1c3bfc9bc Use `maps.Clone(m)` to copy returned map in `APICommands()` (ethereum-optimism#33)
1be4df2a3 Use 'errors.Is' to compare errors (ethereum-optimism#32)
3f6bc5f8e e2e: sync ElectrumX environment variables with infra (ethereum-optimism#36)
c5b0fea01 electrumx: add connection reuse and pooling (ethereum-optimism#26)
cfc1293e9 Update README.md (ethereum-optimism#29)
8896259f0 retry mine keystone on failure (ethereum-optimism#18)
a10e3bb29 Use '%w' verb in fmt.Errorf to wrap errors (fixes ethereum-optimism#13) (ethereum-optimism#27)
6cd677611 deps: update google.golang.org/protobuf to v1.33.0 (ethereum-optimism#28)
ed7eb8e97 ci: fix concurrency cancel-in-progress for pull requests (ethereum-optimism#16)
ac3b7eacb docker: update golang image to v1.22.1 (ethereum-optimism#25)
d6b0ac8af returning response errors if they exist from bfg -> popm (ethereum-optimism#24)
d450b787a Network test start height + no panic (ethereum-optimism#22)
b390805c5 allowing BTC Block and L2 Keystone generation rates to be configurable in local network (ethereum-optimism#19)
bfd3b1dc0 make: add -local flag to goimports (ethereum-optimism#9)
e0e8964fc Move internal error into protocol package (ethereum-optimism#10)
7875a897c l2 keystone mining fixes (#3)

git-subtree-dir: heminetwork
git-subtree-split: 88047e707e2db8522e2ad77c5f849e55bc94cd10
  • Loading branch information
max-sanchez authored and ClaytonNorthey92 committed Apr 17, 2024
1 parent a3e985b commit b6b1308
Show file tree
Hide file tree
Showing 119 changed files with 25,090 additions and 1,822 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

concurrency:
group: "go-${{ github.workflow }}-${{ github.event.number || github.ref }}"
cancel-in-progress: "${{ github.event.action == 'push' || github.event.action == 'pull_request' }}"
cancel-in-progress: "${{ github.event_name == 'pull_request' }}"

permissions:
contents: read
Expand Down Expand Up @@ -60,6 +60,7 @@ jobs:
if: (success() || failure()) && steps.deps.outcome == 'success'
env:
PGTESTURI: "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"
HEMI_DOCKER_TESTS: "1"
run: |
make
git diff --exit-code
Expand Down
72 changes: 70 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,73 @@
### Hemi
/bin/
/dist/
/pkg/
.gocache
*.sw?
/.gocache/

## Tests
/service/tbc/.testleveldb/

### Common editors
## Vim
# Swap
[._]*.s[a-v][a-z]
!*.svg
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

## Emacs
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# network security
/network-security.data

## JetBrains
.idea/
*.iml

## Visual Studio Code
.vscode/
.history/
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@ project = heminetwork
version = $(shell git describe --tags 2>/dev/null || echo "v0.0.0")

cmds = \
bfgd \
bssd \
extool \
keygen \
popmd \
hemictl
bfgd \
bssd \
extool \
hemictl \
keygen \
popmd \
tbcd

.PHONY: all clean clean-dist deps $(cmds) build install lint lint-deps tidy race test vulncheck \
vulncheck-deps dist archive sources checksums networktest

all: lint tidy test build install

clean: clean-dist
clean: clean-dist clean-test
rm -rf $(GOBIN) $(GOCACHE) $(GOPKG)

clean-dist:
rm -rf $(DIST)

clean-test:
rm -rf $(PROJECTPATH)/service/tbc/.testleveldb/

deps: lint-deps vulncheck-deps
go mod download
go mod verify
Expand All @@ -51,13 +55,16 @@ build:
install: $(cmds)

lint:
$(shell go env GOPATH)/bin/goimports -w -l .
$(shell go env GOPATH)/bin/goimports -local github.com/hemilabs/heminetwork -w -l .
$(shell go env GOPATH)/bin/gofumpt -w -l .
$(shell go env GOPATH)/bin/addlicense -c "Hemi Labs, Inc." -f $(PROJECTPATH)/license_header.txt \
-ignore "{.idea,.vscode}/**" -ignore ".github/release.yml" -ignore ".github/ISSUE_TEMPLATE/**" .
go vet ./...

lint-deps:
GOBIN=$(shell go env GOPATH)/bin go install golang.org/x/tools/cmd/goimports@latest
GOBIN=$(shell go env GOPATH)/bin go install mvdan.cc/gofumpt@latest
GOBIN=$(shell go env GOPATH)/bin go install github.com/google/addlicense@latest

tidy:
go mod tidy
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ git clone https://github.com/hemilabs/heminetwork.git
Then build:

```shell
cd heminetwork
make deps
make
```

Expand Down Expand Up @@ -120,15 +122,37 @@ bssd has a few crucial requirements to run:
Prerequisites: `docker`

To run the full network locally, you can run the following. Note that this will create
L2Keytones and BTC Blocks at a high rate. You can modify these in `./e2e/mocktimism/mocktimism.go`
or `./e2e/docker-compose.yml`.
L2Keytones and BTC Blocks at a high rate.

note: the `--build` flag is optional if you want to rebuild your code

```
docker-compose -f ./e2e/docker-compose.yml up --build
docker compose -f ./e2e/docker-compose.yml up --build
```

This will take a while upon first build, but following builds should be cached.
When rebuilding, popmd, bssd, and bfgd will rebuild (due to `COPY` command breaking
the cache). However if you want to break the cache for the op-stack, use the following args:

For op-geth + optimism (op-node)
```
docker compose -f ./e2e/docker-compose.yml build --build-arg OP_GETH_CACHE_BREAK="$(date)"
```

For optimism cache break only:
```
docker compose -f ./e2e/docker-compose.yml build --build-arg OPTIMISM_CACHE_BREAK="$(date)"
```

**IMPORTANT:** make sure you run the following to tear down, this will remove
data and give you a fresh start

```
docker compose -f ./e2e/docker-compose.yml down -v --remove-orphans
```



### Running the full network tests

This runs a test with an entirely local heminet, it uses bitcoind in regtest
Expand All @@ -138,4 +162,4 @@ Prerequisites: `docker`

```
make networktest
```
```
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
)

// hexDecode decodes a string that may be prefixed with " and/or 0x. Thus
// hexDecode decodes a string that may be prefixed with " and/or 0x. Thus,
// "0x00" and 0x00 or 00 are all valid hex encodings. If length is provided the
// decoded size must exactly match. The length parameter will be ignored if it
// is less than 0.
Expand Down
12 changes: 6 additions & 6 deletions api/auth/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (s *Secp256k1Auth) HandshakeClient(ctx context.Context, conn protocol.APICo
for {
_, _, payload, err := protocol.Read(ctx, conn, s)
if err != nil {
return fmt.Errorf("read: %v", err)
return fmt.Errorf("read: %w", err)
}
log.Tracef(spew.Sdump(payload))

Expand All @@ -158,13 +158,13 @@ func (s *Secp256k1Auth) HandshakeClient(ctx context.Context, conn protocol.APICo

hca, err := handleSecp256k1HelloChallenge(s.privKey, c)
if err != nil {
return fmt.Errorf("handleSecp256k1HelloChallenge: %v", err)
return fmt.Errorf("handleSecp256k1HelloChallenge: %w", err)
}

requestID := "HelloChallengeAccepted:" + pubKey
err = protocol.Write(ctx, conn, s, requestID, hca)
if err != nil {
return fmt.Errorf("write HelloChallengeAccepted: %v", err)
return fmt.Errorf("write HelloChallengeAccepted: %w", err)
}

// Exit state machine
Expand All @@ -186,7 +186,7 @@ func (s *Secp256k1Auth) HandshakeServer(ctx context.Context, conn protocol.APICo
for {
_, _, payload, err := protocol.Read(ctx, conn, s)
if err != nil {
return fmt.Errorf("read: %v", err)
return fmt.Errorf("read: %w", err)
}
log.Tracef(spew.Sdump(payload))

Expand All @@ -206,7 +206,7 @@ func (s *Secp256k1Auth) HandshakeServer(ctx context.Context, conn protocol.APICo
err = protocol.Write(ctx, conn, s,
"HelloChallenge:"+c.PublicKey, hc)
if err != nil {
return fmt.Errorf("write HelloChallenge: %v", err)
return fmt.Errorf("write HelloChallenge: %w", err)
}

case *Secp256k1HelloChallengeAccepted:
Expand All @@ -220,7 +220,7 @@ func (s *Secp256k1Auth) HandshakeServer(ctx context.Context, conn protocol.APICo

derived, err := handleSecp256k1HelloChallengeAccepted(am, c)
if err != nil {
return fmt.Errorf("handleSecp256k1HelloChallengeAccepted: %v", err)
return fmt.Errorf("handleSecp256k1HelloChallengeAccepted: %w", err)
}

// Exit state machine
Expand Down
3 changes: 2 additions & 1 deletion api/bfgapi/bfgapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package bfgapi
import (
"context"
"fmt"
"maps"
"reflect"

"github.com/hemilabs/heminetwork/api"
Expand Down Expand Up @@ -223,7 +224,7 @@ func (a *bfgAPI) Commands() map[protocol.Command]reflect.Type {
}

func APICommands() map[protocol.Command]reflect.Type {
return commands // XXX make copy
return maps.Clone(commands)
}

// Write is the low level primitive of a protocol Write. One should generally
Expand Down
3 changes: 2 additions & 1 deletion api/bssapi/bssapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package bssapi
import (
"context"
"fmt"
"maps"
"math/big"
"reflect"

Expand Down Expand Up @@ -134,7 +135,7 @@ func (a *apiCmd) Commands() map[protocol.Command]reflect.Type {
}

func APICommands() map[protocol.Command]reflect.Type {
return commands // XXX make copy
return maps.Clone(commands)
}

// Read reads a command from an APIConn. This is used server side.
Expand Down
Loading

0 comments on commit b6b1308

Please sign in to comment.