aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-26 16:26:38 -0800
committerFuwn <[email protected]>2026-02-26 16:26:38 -0800
commit8b7f7b938aead6ec285c5c9290f9a4305b96521f (patch)
tree3a52bd80d3a0468b3fc96c5b240d02d7b16e8f49
parentfeat: Apply Iku formatting (diff)
downloadplutia-test-8b7f7b938aead6ec285c5c9290f9a4305b96521f.tar.xz
plutia-test-8b7f7b938aead6ec285c5c9290f9a4305b96521f.zip
style: align codebase with official Go idioms
-rw-r--r--cmd/plutia/main.go12
-rw-r--r--internal/api/observability.go12
-rw-r--r--internal/api/plc_compatibility_test.go10
-rw-r--r--internal/api/server.go15
-rw-r--r--internal/api/server_checkpoint_test.go6
-rw-r--r--internal/api/server_hardening_test.go6
-rw-r--r--internal/api/server_integration_test.go10
-rw-r--r--internal/checkpoint/checkpoint.go8
-rw-r--r--internal/checkpoint/checkpoint_test.go4
-rw-r--r--internal/config/config.go6
-rw-r--r--internal/ingest/client.go8
-rw-r--r--internal/ingest/service.go14
-rw-r--r--internal/ingest/service_integration_test.go6
-rw-r--r--internal/ingest/service_order_test.go2
-rw-r--r--internal/merkle/tree.go3
-rw-r--r--internal/state/engine.go2
-rw-r--r--internal/storage/blocklog.go10
-rw-r--r--internal/storage/pebble_store.go24
-rw-r--r--internal/storage/pebble_store_batch_durability_test.go2
-rw-r--r--internal/storage/pebble_store_batch_test.go2
-rw-r--r--internal/verify/verifier.go4
-rw-r--r--internal/verify/verifier_test.go2
22 files changed, 75 insertions, 93 deletions
diff --git a/cmd/plutia/main.go b/cmd/plutia/main.go
index 8939f4f..e3e1a12 100644
--- a/cmd/plutia/main.go
+++ b/cmd/plutia/main.go
@@ -6,6 +6,12 @@ import (
"errors"
"flag"
"fmt"
+ "github.com/Fuwn/plutia/internal/api"
+ "github.com/Fuwn/plutia/internal/checkpoint"
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/ingest"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
"log"
"net/http"
"os"
@@ -17,12 +23,6 @@ import (
"strings"
"syscall"
"time"
- "github.com/Fuwn/plutia/internal/api"
- "github.com/Fuwn/plutia/internal/checkpoint"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/ingest"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
)
var (
diff --git a/internal/api/observability.go b/internal/api/observability.go
index 4654b28..008f5f2 100644
--- a/internal/api/observability.go
+++ b/internal/api/observability.go
@@ -1,6 +1,12 @@
package api
import (
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/ingest"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/client_golang/prometheus/promhttp"
"net"
"net/http"
"os"
@@ -8,12 +14,6 @@ import (
"strings"
"sync"
"time"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/ingest"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
- "github.com/prometheus/client_golang/prometheus"
- "github.com/prometheus/client_golang/prometheus/promhttp"
)
type BuildInfo struct {
diff --git a/internal/api/plc_compatibility_test.go b/internal/api/plc_compatibility_test.go
index b914278..fe7ee82 100644
--- a/internal/api/plc_compatibility_test.go
+++ b/internal/api/plc_compatibility_test.go
@@ -6,6 +6,11 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/json"
+ "github.com/Fuwn/plutia/internal/checkpoint"
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/ingest"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
"io"
"net/http"
"net/http/httptest"
@@ -14,11 +19,6 @@ import (
"strings"
"testing"
"time"
- "github.com/Fuwn/plutia/internal/checkpoint"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/ingest"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
)
func TestPLCCompatibilityGetDIDMatchesStoredDocument(t *testing.T) {
diff --git a/internal/api/server.go b/internal/api/server.go
index 2a3c589..a3ef211 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -6,10 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "net/http"
- "strconv"
- "strings"
- "time"
"github.com/Fuwn/plutia/internal/checkpoint"
"github.com/Fuwn/plutia/internal/config"
"github.com/Fuwn/plutia/internal/ingest"
@@ -17,6 +13,10 @@ import (
"github.com/Fuwn/plutia/internal/storage"
"github.com/Fuwn/plutia/internal/types"
"github.com/Fuwn/plutia/pkg/proof"
+ "net/http"
+ "strconv"
+ "strings"
+ "time"
)
type Server struct {
@@ -772,12 +772,11 @@ func writeJSON(w http.ResponseWriter, code int, v any) {
}
func writeJSONWithContentType(w http.ResponseWriter, code int, contentType string, v any) {
- w.Header().Set("Content-Type", "application/json")
-
- if strings.TrimSpace(contentType) != "" {
- w.Header().Set("Content-Type", contentType)
+ if strings.TrimSpace(contentType) == "" {
+ contentType = "application/json"
}
+ w.Header().Set("Content-Type", contentType)
w.WriteHeader(code)
_ = json.NewEncoder(w).Encode(v)
diff --git a/internal/api/server_checkpoint_test.go b/internal/api/server_checkpoint_test.go
index 531f24d..6b77729 100644
--- a/internal/api/server_checkpoint_test.go
+++ b/internal/api/server_checkpoint_test.go
@@ -1,13 +1,13 @@
package api
import (
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
)
func TestSelectCheckpointForProofDetectsLatestAdvance(t *testing.T) {
diff --git a/internal/api/server_hardening_test.go b/internal/api/server_hardening_test.go
index fcdf87b..065e8a4 100644
--- a/internal/api/server_hardening_test.go
+++ b/internal/api/server_hardening_test.go
@@ -2,15 +2,15 @@ package api
import (
"encoding/json"
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
)
func TestResolveRateLimitPerIP(t *testing.T) {
diff --git a/internal/api/server_integration_test.go b/internal/api/server_integration_test.go
index edb64bd..286afde 100644
--- a/internal/api/server_integration_test.go
+++ b/internal/api/server_integration_test.go
@@ -7,6 +7,11 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
+ "github.com/Fuwn/plutia/internal/checkpoint"
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/ingest"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
"io"
"net/http"
"net/http/httptest"
@@ -14,11 +19,6 @@ import (
"path/filepath"
"strings"
"testing"
- "github.com/Fuwn/plutia/internal/checkpoint"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/ingest"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
)
func TestProofAgainstOlderCheckpointAfterFurtherIngest(t *testing.T) {
diff --git a/internal/checkpoint/checkpoint.go b/internal/checkpoint/checkpoint.go
index 85c4992..e3f4d99 100644
--- a/internal/checkpoint/checkpoint.go
+++ b/internal/checkpoint/checkpoint.go
@@ -10,15 +10,15 @@ import (
"encoding/json"
"errors"
"fmt"
+ "github.com/Fuwn/plutia/internal/merkle"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
+ "github.com/mr-tron/base58"
"os"
"path/filepath"
"sort"
"strings"
"time"
- "github.com/Fuwn/plutia/internal/merkle"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
- "github.com/mr-tron/base58"
)
type Manager struct {
diff --git a/internal/checkpoint/checkpoint_test.go b/internal/checkpoint/checkpoint_test.go
index 156aa9e..fee8dc8 100644
--- a/internal/checkpoint/checkpoint_test.go
+++ b/internal/checkpoint/checkpoint_test.go
@@ -6,11 +6,11 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/json"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
"os"
"path/filepath"
"testing"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
)
func TestBuildAndStoreCheckpoint(t *testing.T) {
diff --git a/internal/config/config.go b/internal/config/config.go
index abb7444..11ac848 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -3,17 +3,17 @@ package config
import (
"errors"
"fmt"
+ "gopkg.in/yaml.v3"
"os"
"runtime"
"strconv"
"strings"
"time"
- "gopkg.in/yaml.v3"
)
const (
- ModeResolver = "resolver"
- ModeMirror = "mirror"
+ ModeResolver = "resolver"
+ ModeMirror = "mirror"
VerifyFull = "full"
VerifyLazy = "lazy"
VerifyStateOnly = "state-only"
diff --git a/internal/ingest/client.go b/internal/ingest/client.go
index 12d8bd6..29457cf 100644
--- a/internal/ingest/client.go
+++ b/internal/ingest/client.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "github.com/Fuwn/plutia/internal/types"
"io"
"log"
"net"
@@ -17,7 +18,6 @@ import (
"strconv"
"strings"
"time"
- "github.com/Fuwn/plutia/internal/types"
)
type Client struct {
@@ -369,11 +369,7 @@ func isSpace(b byte) bool {
}
func (c *Client) fetchFromFile(after uint64, limit uint64) ([]types.ExportRecord, error) {
- path := c.source
-
- if strings.HasPrefix(path, "file://") {
- path = strings.TrimPrefix(path, "file://")
- }
+ path := strings.TrimPrefix(c.source, "file://")
path = filepath.Clean(path)
b, err := os.ReadFile(path)
diff --git a/internal/ingest/service.go b/internal/ingest/service.go
index 1779db9..1ea2a6e 100644
--- a/internal/ingest/service.go
+++ b/internal/ingest/service.go
@@ -5,6 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
+ "github.com/Fuwn/plutia/internal/checkpoint"
+ "github.com/Fuwn/plutia/internal/config"
+ "github.com/Fuwn/plutia/internal/state"
+ "github.com/Fuwn/plutia/internal/storage"
+ "github.com/Fuwn/plutia/internal/types"
+ "github.com/Fuwn/plutia/internal/verify"
"hash/fnv"
"log"
"os"
@@ -15,12 +21,6 @@ import (
"sync"
"sync/atomic"
"time"
- "github.com/Fuwn/plutia/internal/checkpoint"
- "github.com/Fuwn/plutia/internal/config"
- "github.com/Fuwn/plutia/internal/state"
- "github.com/Fuwn/plutia/internal/storage"
- "github.com/Fuwn/plutia/internal/types"
- "github.com/Fuwn/plutia/internal/verify"
)
type Stats struct {
@@ -39,7 +39,6 @@ type Service struct {
store storage.Store
client *Client
verifier *verify.Verifier
- engine *state.Engine
checkpoints *checkpoint.Manager
blockLog *storage.BlockLog
appender *blockAppender
@@ -67,7 +66,6 @@ func NewService(cfg config.Config, store storage.Store, client *Client, blockLog
store: store,
client: client,
verifier: verify.New(cfg.VerifyPolicy),
- engine: state.New(store, cfg.Mode),
checkpoints: checkpointMgr,
blockLog: blockLog,
startedAt: time.Now(),
diff --git a/internal/ingest/service_integration_test.go b/internal/ingest/service_integration_test.go
index 9985367..dc4e699 100644
--- a/internal/ingest/service_integration_test.go
+++ b/internal/ingest/service_integration_test.go
@@ -7,13 +7,13 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
- "os"
- "path/filepath"
- "testing"
"github.com/Fuwn/plutia/internal/checkpoint"
"github.com/Fuwn/plutia/internal/config"
"github.com/Fuwn/plutia/internal/storage"
"github.com/Fuwn/plutia/internal/types"
+ "os"
+ "path/filepath"
+ "testing"
)
func TestReplayIntegration(t *testing.T) {
diff --git a/internal/ingest/service_order_test.go b/internal/ingest/service_order_test.go
index 1d7c766..952e411 100644
--- a/internal/ingest/service_order_test.go
+++ b/internal/ingest/service_order_test.go
@@ -1,8 +1,8 @@
package ingest
import (
- "testing"
"github.com/Fuwn/plutia/internal/types"
+ "testing"
)
func TestCollectVerifiedInOrder_OutOfOrderInput(t *testing.T) {
diff --git a/internal/merkle/tree.go b/internal/merkle/tree.go
index 023b4ec..96f84f8 100644
--- a/internal/merkle/tree.go
+++ b/internal/merkle/tree.go
@@ -1,6 +1,7 @@
package merkle
import (
+ "bytes"
"crypto/sha256"
"encoding/hex"
)
@@ -110,7 +111,7 @@ func VerifyProof(leafHash []byte, proof []Sibling, root []byte) bool {
cur = h[:]
}
- return hex.EncodeToString(cur) == hex.EncodeToString(root)
+ return bytes.Equal(cur, root)
}
func cloneLevel(in [][]byte) [][]byte {
diff --git a/internal/state/engine.go b/internal/state/engine.go
index 0f5caad..221b802 100644
--- a/internal/state/engine.go
+++ b/internal/state/engine.go
@@ -3,10 +3,10 @@ package state
import (
"encoding/json"
"fmt"
- "time"
"github.com/Fuwn/plutia/internal/config"
"github.com/Fuwn/plutia/internal/storage"
"github.com/Fuwn/plutia/internal/types"
+ "time"
)
type Engine struct {
diff --git a/internal/storage/blocklog.go b/internal/storage/blocklog.go
index e343b45..d9bedb3 100644
--- a/internal/storage/blocklog.go
+++ b/internal/storage/blocklog.go
@@ -6,6 +6,8 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
+ "github.com/Fuwn/plutia/internal/types"
+ "github.com/klauspost/compress/zstd"
"os"
"path/filepath"
"sort"
@@ -13,8 +15,6 @@ import (
"strings"
"sync"
"time"
- "github.com/Fuwn/plutia/internal/types"
- "github.com/klauspost/compress/zstd"
)
type FlushInfo struct {
@@ -32,9 +32,9 @@ type BlockLog struct {
dir string
zstdLevel int
targetSize int
- mu sync.Mutex
- buf bytes.Buffer
- blockID uint64
+ mu sync.Mutex
+ buf bytes.Buffer
+ blockID uint64
}
func OpenBlockLog(dataDir string, zstdLevel int, targetMB int) (*BlockLog, error) {
diff --git a/internal/storage/pebble_store.go b/internal/storage/pebble_store.go
index 55c04fb..b0a8e01 100644
--- a/internal/storage/pebble_store.go
+++ b/internal/storage/pebble_store.go
@@ -4,10 +4,10 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
- "path/filepath"
- "sort"
"github.com/Fuwn/plutia/internal/types"
"github.com/cockroachdb/pebble"
+ "path/filepath"
+ "sort"
)
var _ Store = (*PebbleStore)(nil)
@@ -30,9 +30,9 @@ func OpenPebble(dataDir string) (*PebbleStore, error) {
func (p *PebbleStore) Close() error { return p.db.Close() }
func (p *PebbleStore) GetMode() (string, error) {
- v, ok, err := p.getString(metaKey("mode"))
+ v, _, err := p.getString(metaKey("mode"))
- return v, okOrErr(ok, err)
+ return v, err
}
func (p *PebbleStore) SetMode(mode string) error {
@@ -462,11 +462,11 @@ func (p *PebbleStore) getUint64(key []byte) (uint64, bool, error) {
return binary.BigEndian.Uint64(b), true, nil
}
-func didKey(did string) []byte { return []byte("did:" + did) }
+func didKey(did string) []byte { return []byte("did:" + did) }
func chainKey(did string) []byte { return []byte("chain:" + did) }
-func metaKey(k string) []byte { return []byte("meta:" + k) }
+func metaKey(k string) []byte { return []byte("meta:" + k) }
func checkpointKey(s uint64) []byte {
return append([]byte("checkpoint:"), u64bytes(s)...)
@@ -491,15 +491,3 @@ func u64bytes(v uint64) []byte {
return b
}
-
-func okOrErr(ok bool, err error) error {
- if err != nil {
- return err
- }
-
- if !ok {
- return nil
- }
-
- return nil
-}
diff --git a/internal/storage/pebble_store_batch_durability_test.go b/internal/storage/pebble_store_batch_durability_test.go
index 256ddda..dc555cd 100644
--- a/internal/storage/pebble_store_batch_durability_test.go
+++ b/internal/storage/pebble_store_batch_durability_test.go
@@ -1,9 +1,9 @@
package storage
import (
+ "github.com/Fuwn/plutia/internal/types"
"testing"
"time"
- "github.com/Fuwn/plutia/internal/types"
)
func TestApplyOperationsBatch_DurabilityBetweenBatches(t *testing.T) {
diff --git a/internal/storage/pebble_store_batch_test.go b/internal/storage/pebble_store_batch_test.go
index 742e7bf..0690818 100644
--- a/internal/storage/pebble_store_batch_test.go
+++ b/internal/storage/pebble_store_batch_test.go
@@ -1,9 +1,9 @@
package storage
import (
+ "github.com/Fuwn/plutia/internal/types"
"testing"
"time"
- "github.com/Fuwn/plutia/internal/types"
)
func TestPebbleStoreApplyOperationBatch(t *testing.T) {
diff --git a/internal/verify/verifier.go b/internal/verify/verifier.go
index 4cb6b38..bfc5692 100644
--- a/internal/verify/verifier.go
+++ b/internal/verify/verifier.go
@@ -11,14 +11,14 @@ import (
"encoding/json"
"errors"
"fmt"
- "math/big"
- "strings"
"github.com/Fuwn/plutia/internal/config"
"github.com/Fuwn/plutia/internal/types"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
secpECDSA "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
"github.com/fxamacker/cbor/v2"
"github.com/mr-tron/base58"
+ "math/big"
+ "strings"
)
type Verifier struct {
diff --git a/internal/verify/verifier_test.go b/internal/verify/verifier_test.go
index e4f46fa..2046437 100644
--- a/internal/verify/verifier_test.go
+++ b/internal/verify/verifier_test.go
@@ -8,13 +8,13 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
- "testing"
"github.com/Fuwn/plutia/internal/config"
"github.com/Fuwn/plutia/internal/types"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
secpECDSA "github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa"
"github.com/fxamacker/cbor/v2"
"github.com/mr-tron/base58"
+ "testing"
)
func TestVerifyOperationValidSignature(t *testing.T) {