Skip to content

Commit 52c2765

Browse files
committed
Merge remote-tracking branch 'origin/main' into pay-3194-reposts-current-user
* origin/main: (74 commits) Update users endpoints: round 1 (#9166) PAY-3280 Fix gated access display (#9311) [PAY-3276] No scheduled playlists (#9312) [PAY-3262] Fix edit new playlist (#9309) Makefile improvements to core (#9300) Update dn models (#9291) [PAY-3260] Use 'Today' for matching release dates (#9292) [PAY-3258] BoxedTextField can error before form submission (#9305) [PAY-3248][PAY-3256][PAY-3234] Fix misc android issues (#9307) Premium extras updates (#9306) Silence request logs for python es client (#9301) [PAY-3263] add playlists & albums release date if null (#9304) Small FilterButton hover style tweak (#9303) [QA-1448] Fix user badge spacing (#9302) [C-4868] BPM validation (#9295) [C-4854] Add Premium Extras label (#9294) [PAY-3261] Update remix settings copy (#9299) Audius Protocol v0.6.158 Longer deadline for fixing files (#9297) [PAY-3236][PAY-3242][PAY-3259] Fix play button in tracks table (#9288) ...
2 parents 72881e0 + 885479a commit 52c2765

File tree

246 files changed

+5739
-1695
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+5739
-1695
lines changed

.changeset/green-deers-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@audius/harmony': patch
3+
---
4+
5+
Fix active and hover styling for FilterButton

core/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/*.env
2+
*.env
3+
/tmp

core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/tmp

core/Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
SQL_SRCS := $(shell find db/sql/ -type f -name '*.sql') db/sqlc.yaml
2+
3+
.PHONY: up down deps test
4+
up: down gen
5+
cd infra && docker compose up --build -d
6+
7+
down:
8+
cd infra && docker compose down
9+
10+
deps:
11+
@go install github.com/onsi/ginkgo/v2/[email protected]
12+
@brew install protobuf
13+
@go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
14+
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
15+
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
16+
@go mod tidy
17+
18+
gen: $(SQL_SRCS)
19+
@which sqlc || ( \
20+
echo "ERROR: sqlc command not found." \
21+
"Please run 'make deps' to initialize the environment." \
22+
&& false \
23+
)
24+
cd db && sqlc generate
25+
26+
test:
27+
@go test -v ./...
28+
@cd test/integration && ginkgo -r
29+
30+
.PHONY: dev-discovery-1 dev-content-1 dev-content-2 dev-content-3
31+
dev-discovery-1:
32+
@go run main.go -env-file=./infra/dev_config/discovery-one.env
33+
34+
dev-content-1:
35+
@go run main.go -env-file=./infra/dev_config/content-one.env
36+
37+
dev-content-2:
38+
@go run main.go -env-file=./infra/dev_config/content-two.env
39+
40+
dev-content-3:
41+
@go run main.go -env-file=./infra/dev_config/content-three.env
42+

core/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# audius core
2+
3+
The distributed event log that binds discovery, content, and identity together. The audius L1.
4+
5+
## architecture
6+
7+
Built with cometbft, audius core is the L1 blockchain that stores all the canon events in the audius protocol. The core is the library that allows you to build node types around this source, publish events, index data, and materialize views that then power audius applications.
8+
9+
```mermaid
10+
graph TD
11+
L1["Audius L1"]
12+
L2a["Discovery Provider"]
13+
L2b["Content Node"]
14+
L2c["Identity Service"]
15+
16+
L1 --> |"indexes discovery\n related data"| L2a
17+
L1 --> |"indexes content\n related data"| L2b
18+
L1 --> |"indexes identity\n related data"| L2c
19+
20+
```
21+
22+
## configuration
23+
24+
Whether running as an independent image or embedded, core requires some environment variables to run.
25+
26+
### local cluster
27+
28+
### running in production
29+
30+
31+
## testing
32+
33+
To run tests simply run the make command. This will run both unit and integration tests.
34+
35+
```bash
36+
make test
37+
```
38+
39+
### unit tests
40+
41+
Place unit tests next to appropriate files in the standard go fashion
42+
43+
```bash
44+
core/signature.go
45+
core/signature_test.go
46+
```
47+
48+
### integration tests
49+
50+
Integration tests are written with [ginkgo](https://github.com/onsi/ginkgo) and [gomega](https://github.com/onsi/gomega) to be more readable, the way to generate one is to use the ginkgo cli installed in the `make deps` command.
51+
52+
```bash
53+
ginkgo generate NewTestName
54+
```

core/accounts/signature.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package accounts

core/accounts/wallet.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package accounts
2+
3+
import (
4+
"crypto/sha256"
5+
"encoding/hex"
6+
"errors"
7+
8+
"github.com/cometbft/cometbft/crypto/ed25519"
9+
)
10+
11+
func EthToCometKey(hexPkey string) (ed25519.PrivKey, error) {
12+
ethPkeyBytes, err := hex.DecodeString(hexPkey)
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
if len(ethPkeyBytes) != 32 {
18+
return nil, errors.New("private key length not 32")
19+
}
20+
21+
hash := sha256.Sum256(ethPkeyBytes)
22+
eckey := ed25519.GenPrivKeyFromSecret(hash[:])
23+
return eckey, nil
24+
}

core/accounts/wallet_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package accounts

core/chain/abci.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package chain
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"crypto/sha256"
7+
"encoding/hex"
8+
9+
"github.com/AudiusProject/audius-protocol/core/common"
10+
"github.com/AudiusProject/audius-protocol/core/db"
11+
abcitypes "github.com/cometbft/cometbft/abci/types"
12+
"github.com/jackc/pgx/v5"
13+
"github.com/jackc/pgx/v5/pgxpool"
14+
)
15+
16+
type KVStoreApplication struct {
17+
logger *common.Logger
18+
queries *db.Queries
19+
pool *pgxpool.Pool
20+
onGoingBlock pgx.Tx
21+
}
22+
23+
var _ abcitypes.Application = (*KVStoreApplication)(nil)
24+
25+
func NewKVStoreApplication(logger *common.Logger, pool *pgxpool.Pool) *KVStoreApplication {
26+
return &KVStoreApplication{
27+
logger: logger,
28+
queries: db.New(pool),
29+
pool: pool,
30+
onGoingBlock: nil,
31+
}
32+
}
33+
34+
func (app *KVStoreApplication) Info(_ context.Context, info *abcitypes.InfoRequest) (*abcitypes.InfoResponse, error) {
35+
return &abcitypes.InfoResponse{}, nil
36+
}
37+
38+
func (app *KVStoreApplication) Query(ctx context.Context, req *abcitypes.QueryRequest) (*abcitypes.QueryResponse, error) {
39+
resp := abcitypes.QueryResponse{Key: req.Data}
40+
41+
kv, err := app.queries.GetKey(ctx, string(req.Data))
42+
if err != nil {
43+
resp.Log = err.Error()
44+
return &resp, err
45+
}
46+
47+
value := []byte(kv.Value)
48+
resp.Log = "exists"
49+
resp.Value = value
50+
51+
return &resp, nil
52+
}
53+
54+
func (app *KVStoreApplication) CheckTx(_ context.Context, check *abcitypes.CheckTxRequest) (*abcitypes.CheckTxResponse, error) {
55+
code := app.isValid(check.Tx)
56+
return &abcitypes.CheckTxResponse{Code: code}, nil
57+
}
58+
59+
func (app *KVStoreApplication) InitChain(_ context.Context, chain *abcitypes.InitChainRequest) (*abcitypes.InitChainResponse, error) {
60+
return &abcitypes.InitChainResponse{}, nil
61+
}
62+
63+
func (app *KVStoreApplication) PrepareProposal(_ context.Context, proposal *abcitypes.PrepareProposalRequest) (*abcitypes.PrepareProposalResponse, error) {
64+
return &abcitypes.PrepareProposalResponse{Txs: proposal.Txs}, nil
65+
}
66+
67+
func (app *KVStoreApplication) ProcessProposal(_ context.Context, proposal *abcitypes.ProcessProposalRequest) (*abcitypes.ProcessProposalResponse, error) {
68+
return &abcitypes.ProcessProposalResponse{Status: abcitypes.PROCESS_PROPOSAL_STATUS_ACCEPT}, nil
69+
}
70+
71+
func (app *KVStoreApplication) FinalizeBlock(ctx context.Context, req *abcitypes.FinalizeBlockRequest) (*abcitypes.FinalizeBlockResponse, error) {
72+
logger := app.logger
73+
var txs = make([]*abcitypes.ExecTxResult, len(req.Txs))
74+
75+
// early out if empty block
76+
if len(txs) == 0 {
77+
return &abcitypes.FinalizeBlockResponse{
78+
TxResults: txs,
79+
}, nil
80+
}
81+
82+
// open in progres pg transaction
83+
app.startInProgressTx(ctx)
84+
for i, tx := range req.Txs {
85+
if code := app.isValid(tx); code != 0 {
86+
logger.Errorf("Error: invalid transaction index %v", i)
87+
txs[i] = &abcitypes.ExecTxResult{Code: code}
88+
} else {
89+
parts := bytes.SplitN(tx, []byte("="), 2)
90+
key, value := parts[0], parts[1]
91+
logger.Infof("Adding key %s with value %s", key, value)
92+
93+
qtx := app.getDb()
94+
95+
hash := sha256.Sum256(tx)
96+
txHash := hex.EncodeToString(hash[:])
97+
98+
params := db.InsertKVStoreParams{
99+
Key: string(key),
100+
Value: string(value),
101+
TxHash: txHash,
102+
}
103+
104+
record, err := qtx.InsertKVStore(ctx, params)
105+
if err != nil {
106+
logger.Errorf("failed to persisted kv entry %v", err)
107+
}
108+
109+
txs[i] = &abcitypes.ExecTxResult{
110+
Code: 0,
111+
Events: []abcitypes.Event{
112+
{
113+
Type: "app",
114+
Attributes: []abcitypes.EventAttribute{
115+
{Key: "key", Value: record.Key, Index: true},
116+
{Key: "value", Value: record.Value, Index: true},
117+
},
118+
},
119+
},
120+
}
121+
}
122+
}
123+
124+
return &abcitypes.FinalizeBlockResponse{
125+
TxResults: txs,
126+
}, nil
127+
}
128+
129+
func (app KVStoreApplication) Commit(ctx context.Context, commit *abcitypes.CommitRequest) (*abcitypes.CommitResponse, error) {
130+
app.logger.Info("in commit phase", "onGoingBlock", app.onGoingBlock)
131+
if err := app.commitInProgressTx(ctx); err != nil {
132+
app.logger.Error("failure to commit tx", "error", err)
133+
return &abcitypes.CommitResponse{}, err
134+
}
135+
return &abcitypes.CommitResponse{}, nil
136+
}
137+
138+
func (app *KVStoreApplication) ListSnapshots(_ context.Context, snapshots *abcitypes.ListSnapshotsRequest) (*abcitypes.ListSnapshotsResponse, error) {
139+
return &abcitypes.ListSnapshotsResponse{}, nil
140+
}
141+
142+
func (app *KVStoreApplication) OfferSnapshot(_ context.Context, snapshot *abcitypes.OfferSnapshotRequest) (*abcitypes.OfferSnapshotResponse, error) {
143+
return &abcitypes.OfferSnapshotResponse{}, nil
144+
}
145+
146+
func (app *KVStoreApplication) LoadSnapshotChunk(_ context.Context, chunk *abcitypes.LoadSnapshotChunkRequest) (*abcitypes.LoadSnapshotChunkResponse, error) {
147+
return &abcitypes.LoadSnapshotChunkResponse{}, nil
148+
}
149+
150+
func (app *KVStoreApplication) ApplySnapshotChunk(_ context.Context, chunk *abcitypes.ApplySnapshotChunkRequest) (*abcitypes.ApplySnapshotChunkResponse, error) {
151+
return &abcitypes.ApplySnapshotChunkResponse{Result: abcitypes.APPLY_SNAPSHOT_CHUNK_RESULT_ACCEPT}, nil
152+
}
153+
154+
func (app KVStoreApplication) ExtendVote(_ context.Context, extend *abcitypes.ExtendVoteRequest) (*abcitypes.ExtendVoteResponse, error) {
155+
return &abcitypes.ExtendVoteResponse{}, nil
156+
}
157+
158+
func (app *KVStoreApplication) VerifyVoteExtension(_ context.Context, verify *abcitypes.VerifyVoteExtensionRequest) (*abcitypes.VerifyVoteExtensionResponse, error) {
159+
return &abcitypes.VerifyVoteExtensionResponse{}, nil
160+
}
161+
162+
func (app *KVStoreApplication) isValid(tx []byte) uint32 {
163+
// check format
164+
parts := bytes.Split(tx, []byte("="))
165+
if len(parts) != 2 {
166+
return 1
167+
}
168+
169+
return 0
170+
}

core/chain/db.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package chain
2+
3+
import (
4+
"context"
5+
"errors"
6+
7+
"github.com/AudiusProject/audius-protocol/core/db"
8+
"github.com/jackc/pgx/v5"
9+
)
10+
11+
// returns in current postgres tx for this block
12+
func (c *KVStoreApplication) getDb() *db.Queries {
13+
return c.queries.WithTx(c.onGoingBlock)
14+
}
15+
16+
func (c *KVStoreApplication) startInProgressTx(ctx context.Context) error {
17+
dbTx, err := c.pool.Begin(ctx)
18+
if err != nil {
19+
return err
20+
}
21+
22+
c.onGoingBlock = dbTx
23+
return nil
24+
}
25+
26+
// commits the current tx that's finished indexing
27+
func (c *KVStoreApplication) commitInProgressTx(ctx context.Context) error {
28+
if c.onGoingBlock != nil {
29+
err := c.onGoingBlock.Commit(ctx)
30+
if err != nil {
31+
if errors.Is(err, pgx.ErrTxClosed) {
32+
c.onGoingBlock = nil
33+
return nil
34+
}
35+
return err
36+
}
37+
c.onGoingBlock = nil
38+
}
39+
return nil
40+
}

0 commit comments

Comments
 (0)