Skip to content

Commit

Permalink
Merge pull request #64 from RiemaLabs/chore/lints
Browse files Browse the repository at this point in the history
chore: lint fixes
  • Loading branch information
archidoge0 authored May 27, 2024
2 parents 898b02f + dca6810 commit 21047cf
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 71 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: stable
- name: Build
run:
make ci
35 changes: 0 additions & 35 deletions .github/workflows/main.yml

This file was deleted.

32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
VERSION := $(shell git describe --tags 2>/dev/null)
GIT_HASH := $(shell git rev-parse --short HEAD)

GOOS :=
GOARCH :=
ENV := GOOS=${GOOS} GOARCH=${GOARCH}

LDFLAGS := \
-X main.version=${VERSION} \
-X main.gitHash=${GIT_HASH}
FLAGS := -ldflags='${LDFLAGS}'

.PHONY: build
build: modular-indexer-committee

modular-indexer-committee:
env ${ENV} go build ${FLAGS} -o $@

config.json: config.example.json
cp config.example.json config.json

.PHONY: ci
ci: config.json
go run github.com/RiemaLabs/nubit-ci/cmd/nubitci-lint@latest

.PHONY: ci-fix
ci-fix: config.json
go run github.com/RiemaLabs/nubit-ci/cmd/nubitci-lint@latest -w

.PHONY: clean
clean:
rm -rf ./modular-indexer-committee
6 changes: 5 additions & 1 deletion apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package apis

import (
"encoding/base64"
"errors"
"fmt"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -259,5 +261,7 @@ func StartService(queue *stateless.Queue, enableCommittee, enableDebug, enablePp
}

// TODO: Medium. Allow user to setup port.
r.Run(":8080")
if err := r.Run(":8080"); !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion apis/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func GeneratePostRoot(rootC *verkle.Point, blockHeight uint, resp *Brc20Verifiab
if resp.Proof != nil {
preProofBytes, _ := base64.StdEncoding.DecodeString(*resp.Proof)
preVerkleProof := &verkle.VerkleProof{}
preVerkleProof.UnmarshalJSON(preProofBytes)
_ = preVerkleProof.UnmarshalJSON(preProofBytes)

stateDiff := make([]verkle.StemStateDiff, 0)
for _, s := range resp.Result.StateDiff {
Expand Down
8 changes: 4 additions & 4 deletions cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"

"github.com/spf13/cobra"
Expand All @@ -26,15 +27,14 @@ func NewRuntimeArguments() *RuntimeArguments {

func (arguments *RuntimeArguments) MakeCmd() *cobra.Command {
var rootCmd = &cobra.Command{
Use: "Nubit Committee Indexer",
Use: "modular-indexer-committee",
Short: "Activates the Nubit Committee Indexer with optional services.",
Long: `
Committee Indexer is an essential component of the Nubit Modular Indexer architecture.
Long: `Committee Indexer is an essential component of the Nubit Modular Indexer architecture.
This command offers multiple flags to tailor the indexer's functionality according to the user's needs.
The indexer operates on a fully user-verified execution layer for meta-protocols on Bitcoin,
leveraging Bitcoin's immutable and decentralized nature to provide a Turing-complete execution layer.
`,

Version: fmt.Sprintf("%v (%v)", version, gitHash),
Run: func(cmd *cobra.Command, args []string) {
if arguments.EnableService {
log.Println("Service mode is enabled")
Expand Down
5 changes: 1 addition & 4 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ type Config struct {
} `json:"da"`
} `json:"report"`
Service struct {
Name string `json:"name"`
Name string `json:"name"`
URL string `json:"url"`
MetaProtocol string `json:"metaProtocol"`
} `json:"service"`
}

// Version Control
var Version string

var GlobalConfig Config
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
"github.com/RiemaLabs/modular-indexer-committee/ord/stateless"
)

var (
version = "latest"
gitHash = "unknown"
)

func CatchupStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, initHeight uint, latestHeight uint) (*stateless.Queue, error) {
metrics.Stage.Set(metrics.StageCatchup)

Expand All @@ -45,7 +50,7 @@ func CatchupStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, initH
case <-sigChan:
// SIGINT received, stop the catch-up process
log.Printf("Saving cache file. Please don't force exit.")
stateless.StoreHeader(header, header.Height-2000)
_ = stateless.StoreHeader(header, header.Height-2000)
os.Exit(0)
default:
ordTransfer, err := ordGetter.GetOrdTransfers(i)
Expand All @@ -54,7 +59,7 @@ func CatchupStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, initH
}
header.Lock()
stateless.Exec(header, ordTransfer, i)
header.Paging(ordGetter, false, stateless.NodeResolveFn)
_ = header.Paging(ordGetter, false, stateless.NodeResolveFn)
header.Unlock()
if i%1000 == 0 {
log.Printf("Blocks: %d / %d \n", i, catchupHeight)
Expand Down Expand Up @@ -184,7 +189,7 @@ func ServiceStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, queue
indexerID := checkpoint.IndexerIdentification{
URL: serviceURL,
Name: committeeIndexerName,
Version: Version,
Version: version,
MetaProtocol: metaProtocol,
}
commitment := base64.StdEncoding.EncodeToString(i.VerkleCommit[:])
Expand Down Expand Up @@ -226,11 +231,8 @@ func ServiceStage(ordGetter getter.OrdGetter, arguments *RuntimeArguments, queue
}

func Execution(arguments *RuntimeArguments) {
// TODO: High. Get the version from Git Tag.
Version = "v0.2.0"

go metrics.ListenAndServe(arguments.MetricAddr)
metrics.Version.WithLabelValues(Version).Set(1)
metrics.Version.WithLabelValues(version).Set(1)
metrics.Stage.Set(metrics.StageInitializing)

// Get the configuration.
Expand Down
2 changes: 1 addition & 1 deletion ord/stateless/brc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func Exec(state KVStorage, ots []getter.OrdTransfer, blockHeight uint) {
inscriptionID, oldSatpoint, newPkscript, newWallet, sentAsFee, content, contentType, parentID :=
ot.InscriptionID, ot.OldSatpoint, ot.NewPkscript, ot.NewWallet, ot.SentAsFee, ot.Content, ot.ContentType, ot.ParentID
var js map[string]string
json.Unmarshal(content, &js)
_ = json.Unmarshal(content, &js)
if sentAsFee && oldSatpoint == "" {
continue // inscribed as fee
}
Expand Down
2 changes: 1 addition & 1 deletion ord/stateless/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (h *Header) GetBytes(key []byte) []byte {
func (h *Header) Paging(ordGetter getter.OrdGetter, queryHash bool, nodeResolverFn verkle.NodeResolverFn) error {
for key, value := range h.IntermediateKV {
h.KV[key] = value
h.Root.Insert(key[:], value[:], nodeResolverFn)
_ = h.Root.Insert(key[:], value[:], nodeResolverFn)
}

h.Access = AccessList{}
Expand Down
2 changes: 1 addition & 1 deletion ord/stateless/light_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (h *LightHeader) insert(key []byte, value []byte, nodeResolverFn verkle.NodeResolverFn) {
h.Root.Insert(key, value, nodeResolverFn)
_ = h.Root.Insert(key, value, nodeResolverFn)
}

func (h *LightHeader) get(key []byte, nodeResolverFn verkle.NodeResolverFn) []byte {
Expand Down
10 changes: 5 additions & 5 deletions ord/stateless/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (queue *Queue) Update(getter getter.OrdGetter, latestHeight uint) error {
}

queue.Header.OrdTrans = ordTransfer
queue.Header.Paging(getter, true, NodeResolveFn)
_ = queue.Header.Paging(getter, true, NodeResolveFn)
}
return nil
}
Expand All @@ -106,7 +106,7 @@ func Rollingback(header *Header, stateDiff *DiffState) (verkle.VerkleNode, [][]b

rollback := verkle.New()
for k, v := range kvMap {
rollback.Insert(k[:], v[:], NodeResolveFn)
_ = rollback.Insert(k[:], v[:], NodeResolveFn)
}
// The call of Commit is necessary to refresh the root commit.
rollback.Commit()
Expand Down Expand Up @@ -148,7 +148,7 @@ func (queue *Queue) Recovery(getter getter.OrdGetter, reorgHeight uint) error {
}
newRoot := verkle.New()
for k, v := range queue.Header.KV {
newRoot.Insert(k[:], v[:], NodeResolveFn)
_ = newRoot.Insert(k[:], v[:], NodeResolveFn)
}
newBytes := newRoot.Commit().Bytes()
n := base64.StdEncoding.EncodeToString(newBytes[:])
Expand Down Expand Up @@ -188,7 +188,7 @@ func (queue *Queue) Recovery(getter getter.OrdGetter, reorgHeight uint) error {
VerkleCommit: queue.Header.Root.Commit().Bytes(),
}
queue.Header.OrdTrans = ordTransfer
queue.Header.Paging(getter, true, NodeResolveFn)
_ = queue.Header.Paging(getter, true, NodeResolveFn)
}

return nil
Expand Down Expand Up @@ -240,7 +240,7 @@ func NewQueues(getter getter.OrdGetter, header *Header, queryHash bool, startHei
if i == startHeight+ord.BitcoinConfirmations-1 {
proof, _ = generateProofFromUpdate(header, &stateList[i-startHeight])
}
header.Paging(getter, true, NodeResolveFn)
_ = header.Paging(getter, true, NodeResolveFn)
}
// The call of Commit is necessary to refresh the root commit.
header.Root.Commit()
Expand Down
2 changes: 1 addition & 1 deletion reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func loadReorg(getter getter.OrdGetter, queue *stateless.Queue, recovery uint) {
curHeight := queue.Header.Height
// reorgHeights means that the blockHash of this height changed.
reorgHeight := curHeight - recovery + 1
queue.Recovery(getter, reorgHeight)
_ = queue.Recovery(getter, reorgHeight)

for i, h := range queue.History {
newBytes := h.VerkleCommit
Expand Down
12 changes: 2 additions & 10 deletions test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"log"
"os"
"runtime/debug"

"github.com/RiemaLabs/modular-indexer-committee/ord/getter"
)
Expand All @@ -18,13 +17,6 @@ func loadMain(hashedHeight uint) (*getter.OPIOrdGetterTest, RuntimeArguments) {
TestBlockHeightLimit: 0,
}

// Get the version as a stamp for the checkpoint.
bi, ok := debug.ReadBuildInfo()
if !ok {
log.Fatalf("Failed to obtain build information.")
}
Version = bi.Main.Version

// Get the configuration.
configFile, err := os.ReadFile("config.json")
if err != nil {
Expand All @@ -38,11 +30,11 @@ func loadMain(hashedHeight uint) (*getter.OPIOrdGetterTest, RuntimeArguments) {

// Use OPI database as the getter.
gd := getter.DatabaseConfig(GlobalConfig.Database)
getter, err := getter.NewOPIOrdGetterTest(&gd, arguments.TestBlockHeightLimit, hashedHeight)
g, err := getter.NewOPIOrdGetterTest(&gd, arguments.TestBlockHeightLimit, hashedHeight)

if err != nil {
log.Fatalf("Failed to catchup the latest state: %v", err)
}

return getter, arguments
return g, arguments
}

0 comments on commit 21047cf

Please sign in to comment.