Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ jobs:
- run: scripts/install-dev-dependencies.sh
- run: make test-no-db

fuzz-test:
name: Fuzz Test (non DB)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: scripts/install-dev-dependencies.sh
- run: make test-fuzz

db-test:
name: Requires and Core DB Tests (postgres)
runs-on: ubuntu-latest
Expand Down
5 changes: 2 additions & 3 deletions .sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ templater = placeholder
# See https://docs.sqlfluff.com/en/stable/perma/rule_disabling.html
# AM04 (ambiguous.column_count) and ST06 (structure.column_order) are
# two of the more controversial rules included to illustrate usage.
exclude_rules = ambiguous.column_count, structure.column_order
exclude_rules = ambiguous.column_count, structure.column_order, LT01, LT02

# The standard max_line_length is 80 in line with the convention of
# other tools and several style guides. Many projects however prefer
Expand Down Expand Up @@ -72,10 +72,9 @@ extended_capitalisation_policy = upper
preferred_not_equal_style = c_style

[sqlfluff:templater:placeholder]
param_regex = %\[\d+\]s
param_regex = \$\{(?P<param_name>[\w_]+)\}

[sqlfluff:rules]
allow_scalar = True
single_table_references = consistent
unquoted_identifiers_policy = none

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ test-core-db: build
test-requires-db: build
@$(go_test) ${REQUIRES_DB_PACKAGES} | gotestfmt ${GO_TEST_FMT_FLAGS}

# Tests the ASN.1 marshalling using fuzz testing.
test-fuzz: build
@$(go_test) -run="^$$" -fuzz=".*" -fuzztime=5m ./utils/signature | gotestfmt ${GO_TEST_FMT_FLAGS}

# Tests that require no DB at all, e.g., pure logic, utilities
test-no-db: build
@$(go_test) ${NO_DB_PACKAGES} | gotestfmt ${GO_TEST_FMT_FLAGS}
Expand Down Expand Up @@ -157,6 +161,10 @@ bench-dep: FORCE
bench-preparer: FORCE
$(go_cmd) test ./service/vc/... -bench "BenchmarkPrepare.*" -run "^$$" | awk -f scripts/bench-tx-per-sec.awk

# Run signature benchmarks with added op/sec column.
bench-sign: FORCE
$(go_cmd) test ./utils/signature/... -bench ".*" -run "^$$" | awk -f scripts/bench-tx-per-sec.awk

#########################
# Generate protos
#########################
Expand Down
248 changes: 121 additions & 127 deletions api/protoblocktx/block_tx.pb.go

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions api/protoblocktx/block_tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ message Tx {
// Represents a namespace within a transaction.
message TxNamespace {
string ns_id = 1; // The namespace ID.
bytes ns_version = 2; // The version of the namespace.
uint64 ns_version = 2; // The version of the namespace.
Comment thread
liran-funaro marked this conversation as resolved.
repeated Read reads_only = 3; // List of read only operations within the namespace.
repeated ReadWrite read_writes = 4; // List of read-write operations within the namespace.
repeated Write blind_writes = 5; // List of blind write operations within the namespace.
Expand All @@ -29,23 +29,19 @@ message TxNamespace {
// Represents a read operation.
message Read {
bytes key = 1; // The key being read.
bytes version = 2; // The version of the key being read.
optional uint64 version = 2; // The version of the key being read. Nil version means it doesn't exist.
}

// Represents a read-write operation.
message ReadWrite {
bytes key = 1; // The key involved in the read-write operation.
// If the key is empty, the key would be constructed using the txID
// and the index of the read-write operation.
bytes version = 2; // The version of the key being read and written.
optional uint64 version = 2; // The version of the key being read and written. Nil version means it doesn't exist.
bytes value = 3; // The value associated with the key being written.
}

// Represents a write operation.
message Write {
bytes key = 1; // The key being written.
// If the key is empty, the key would be constructed using the txID
// and the index of the read-write operation.
bytes value = 2; // The value associated with the key being written.
}

Expand Down Expand Up @@ -84,12 +80,12 @@ message NamespacePolicies {
message PolicyItem {
string namespace = 1;
bytes policy = 2;
bytes version = 3;
uint64 version = 3;
}

message ConfigTransaction {
bytes envelope = 1;
bytes version = 2;
uint64 version = 2;
}

enum Status {
Expand All @@ -101,7 +97,6 @@ enum Status {
ABORTED_DUPLICATE_NAMESPACE = 5;
ABORTED_NAMESPACE_POLICY_INVALID = 6;
ABORTED_NAMESPACE_ID_INVALID = 7;
ABORTED_MISSING_NAMESPACE_VERSION = 8;
ABORTED_BLIND_WRITES_NOT_ALLOWED = 9;
ABORTED_NO_WRITES = 10;
ABORTED_UNSUPPORTED_TX_PAYLOAD = 11;
Expand Down
8 changes: 4 additions & 4 deletions api/protoqueryservice/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/protoqueryservice/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ message RowsNamespace {
message Row {
bytes key = 1;
bytes value = 2;
bytes version = 3;
uint64 version = 3;
}

message Empty {}
10 changes: 10 additions & 0 deletions api/types/height.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package types
import (
"fmt"

"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
"github.com/hyperledger/fabric-x-committer/utils"
)

Expand All @@ -18,6 +19,15 @@ type Height struct {
TxNum uint32
}

// CreateStatusWithHeight creates a protoblocktx.StatusWithHeight with the given values.
func CreateStatusWithHeight(s protoblocktx.Status, blkNum uint64, txNum int) *protoblocktx.StatusWithHeight {
return &protoblocktx.StatusWithHeight{
Code: s,
BlockNumber: blkNum,
TxNumber: uint32(txNum), //nolint:gosec
}
}

// NewHeight constructs a new instance of Height.
func NewHeight(blockNum uint64, txNum uint32) *Height {
return &Height{blockNum, txNum}
Expand Down
32 changes: 3 additions & 29 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ SPDX-License-Identifier: Apache-2.0

package types

import (
"google.golang.org/protobuf/encoding/protowire"

"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
)

type (
// VersionNumber represents a row's version.
VersionNumber uint64
)

const (
// MetaNamespaceID is the system's namespace ID that holds information about application's namespaces.
MetaNamespaceID = "_meta"
Comment thread
cendhu marked this conversation as resolved.
Expand All @@ -27,22 +16,7 @@ const (
ConfigKey = "_config"
)

// Bytes converts a version number representation to bytes representation.
func (v VersionNumber) Bytes() []byte {
return protowire.AppendVarint(nil, uint64(v))
}

// VersionNumberFromBytes converts a version bytes representation to a number representation.
func VersionNumberFromBytes(version []byte) VersionNumber {
v, _ := protowire.ConsumeVarint(version)
return VersionNumber(v)
}

// CreateStatusWithHeight creates a protoblocktx.StatusWithHeight with the given values.
func CreateStatusWithHeight(s protoblocktx.Status, blkNum uint64, txNum int) *protoblocktx.StatusWithHeight {
return &protoblocktx.StatusWithHeight{
Code: s,
BlockNumber: blkNum,
TxNumber: uint32(txNum), //nolint:gosec
}
// Version is a convenient method to create a version pointer in a single line.
func Version(version uint64) *uint64 {
return &version
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3
github.com/hyperledger/fabric-x-common v0.0.0-20250701155113-a1ddf93333d8
github.com/jackc/pgtype v1.14.3
github.com/jackc/puddle v1.3.0
github.com/mitchellh/mapstructure v1.5.0
github.com/onsi/gomega v1.34.2
Expand Down Expand Up @@ -91,6 +90,7 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgtype v1.14.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/klauspost/compress v1.17.10 // indirect
Expand Down
2 changes: 1 addition & 1 deletion integration/runner/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (c *CommitterRuntime) CreateMetaTX(t *testing.T, namespaces ...string) *pro
t.Helper()
writeToMetaNs := &protoblocktx.TxNamespace{
NsId: types.MetaNamespaceID,
NsVersion: types.VersionNumber(0).Bytes(),
NsVersion: 0,
ReadWrites: make([]*protoblocktx.ReadWrite, 0, len(namespaces)),
}

Expand Down
5 changes: 2 additions & 3 deletions integration/test/config_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestConfigUpdate(t *testing.T) {

c.CreateNamespacesAndCommit(t, "1")

v0 := types.VersionNumber(0).Bytes()
sendTXs := func() {
expected := &runner.ExpectedStatusInBlock{
TxIDs: make([]string, blockSize),
Expand All @@ -77,7 +76,7 @@ func TestConfigUpdate(t *testing.T) {
Id: expected.TxIDs[i],
Namespaces: []*protoblocktx.TxNamespace{{
NsId: "1",
NsVersion: v0,
NsVersion: 0,
BlindWrites: []*protoblocktx.Write{{Key: []byte(fmt.Sprintf("key-%d", i))}},
}},
}
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestConfigUpdate(t *testing.T) {

// We replace the ID to prevent duplicated status, and re-sign it with the correct key.
metaTX.Id = uuid.New().String()
metaTX.Namespaces[0].NsVersion = types.VersionNumber(1).Bytes()
metaTX.Namespaces[0].NsVersion = 1
c.AddSignatures(t, metaTX)
c.SendTransactionsToOrderer(t, []*protoblocktx.Tx{metaTX})
c.ValidateExpectedResultsInCommittedBlock(t, &runner.ExpectedStatusInBlock{
Expand Down
Loading