Skip to content

Commit 7d60273

Browse files
committed
finish libp2p init, fix tests
1 parent d2b3800 commit 7d60273

File tree

8 files changed

+58
-471
lines changed

8 files changed

+58
-471
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ debug: build
134134
all: build
135135
.PHONY: all
136136

137-
build: curio
137+
build: curio sptool
138138
@[[ $$(type -P "curio") ]] && echo "Caution: you have \
139139
an existing curio binary in your PATH. This may cause problems if you don't run 'sudo make install'" || true
140140

cmd/curio/rpc/rpc.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ func (p *CurioAPI) LogSetLevel(ctx context.Context, subsystem, level string) err
250250
}
251251

252252
func ListenAndServe(ctx context.Context, dependencies *deps.Deps, shutdownChan chan struct{}) error {
253-
log.Errorf("ENTERED RPC SERVER")
254253
fh := &paths.FetchHandler{Local: dependencies.LocalStore, PfHandler: &paths.DefaultPartialFileHandler{}}
255254
remoteHandler := func(w http.ResponseWriter, r *http.Request) {
256255
if !auth.HasPerm(r.Context(), nil, lapi.PermAdmin) {
@@ -262,8 +261,6 @@ func ListenAndServe(ctx context.Context, dependencies *deps.Deps, shutdownChan c
262261
fh.ServeHTTP(w, r)
263262
}
264263

265-
log.Errorf("CREATED STORAGE HANDLER")
266-
267264
var authVerify func(context.Context, string) ([]auth.Permission, error)
268265
{
269266
privateKey, err := base64.StdEncoding.DecodeString(dependencies.Cfg.Apis.StorageRPCSecret)

cmd/curio/run.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ var runCmd = &cli.Command{
130130
}
131131
defer taskEngine.GracefullyTerminate()
132132

133-
log.Infof("WILL START RPC SERVER NOW")
134133
err = rpc.ListenAndServe(ctx, dependencies, shutdownChan) // Monitor for shutdown.
135134
if err != nil {
136135
return err

deps/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ type IndexingConfig struct {
638638
type Libp2pConfig struct {
639639
// Miners ID for which MK12 deals (boosts) should be disabled
640640
DisabledMiners []string
641+
641642
// Binding address for the libp2p host - 0 means random port.
642643
// Format: multiaddress; see https://multiformats.io/multiaddr/
643644
ListenAddresses []string

harmony/harmonydb/sql/20240228-piece-park.sql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,5 @@ create table parked_piece_refs (
3333
data_url text,
3434
data_headers jsonb not null default '{}',
3535

36-
-- host Added in 202240730-market-migrations.sql
37-
<<<<<<< HEAD
38-
-- host text,
39-
=======
40-
host text,
41-
>>>>>>> 48e953d (poller redesign)
42-
4336
foreign key (piece_id) references parked_pieces(id) on delete cascade
4437
);

harmony/harmonydb/sql/20240730-market-migration.sql

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ CREATE TABLE market_piece_metadata (
4040
piece_cid TEXT NOT NULL PRIMARY KEY,
4141

4242
version INT NOT NULL DEFAULT 2,
43-
<<<<<<< HEAD
4443
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
45-
=======
46-
47-
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE('UTC', NOW()),
48-
>>>>>>> d1327dc (incomplete basic UI code)
4944

5045
indexed BOOLEAN NOT NULL DEFAULT FALSE,
5146
indexed_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP AT TIME ZONE 'UTC',
@@ -244,7 +239,8 @@ CREATE TABLE market_offline_urls (
244239
CONSTRAINT market_offline_urls_uuid_unique UNIQUE (uuid)
245240
);
246241

247-
CREATE TABLE libp2p_keys (
242+
-- This table is used for coordinating libp2p nodes
243+
CREATE TABLE libp2p (
248244
sp_id BIGINT NOT NULL,
249245
priv_key BYTEA NOT NULL,
250246
listen_address TEXT NOT NULL,
@@ -272,6 +268,60 @@ CREATE TABLE direct_deals (
272268
keep_unsealed_copy BOOLEAN
273269
);
274270

271+
-- -- Function used to update the libp2p table
272+
CREATE OR REPLACE FUNCTION insert_or_update_libp2p(
273+
_sp_id BIGINT,
274+
_listen_address TEXT,
275+
_announce_address TEXT,
276+
_no_announce_address TEXT,
277+
_running_on TEXT
278+
)
279+
RETURNS BYTEA AS $$
280+
DECLARE
281+
_priv_key BYTEA;
282+
_current_running_on TEXT;
283+
_current_updated_at TIMESTAMPTZ;
284+
BEGIN
285+
-- Check if the sp_id exists and retrieve the current values
286+
SELECT priv_key, running_on, updated_at INTO _priv_key, _current_running_on, _current_updated_at
287+
FROM libp2p
288+
WHERE sp_id = _sp_id;
289+
290+
-- Raise an exception if no row was found
291+
IF NOT FOUND THEN
292+
RAISE EXCEPTION 'libp2p key for sp_id "%" does not exist', _sp_id;
293+
END IF;
294+
295+
-- If the sp_id exists and running_on is NULL or matches _running_on
296+
IF _current_running_on IS NULL OR _current_running_on = _running_on THEN
297+
-- Update the record with the provided values and set updated_at to NOW
298+
UPDATE libp2p
299+
SET
300+
listen_address = _listen_address,
301+
announce_address = _announce_address,
302+
no_announce_address = _no_announce_address,
303+
running_on = _running_on,
304+
updated_at = NOW() AT TIME ZONE 'UTC'
305+
WHERE sp_id = _sp_id;
306+
ELSIF _current_updated_at > NOW() - INTERVAL '10 seconds' THEN
307+
-- Raise an exception if running_on is different and updated_at is recent
308+
RAISE EXCEPTION 'Libp2p node already running on "%"', _current_running_on;
309+
ELSE
310+
-- Update running_on and other columns if updated_at is older than 10 seconds
311+
UPDATE libp2p
312+
SET
313+
listen_address = _listen_address,
314+
announce_address = _announce_address,
315+
no_announce_address = _no_announce_address,
316+
running_on = _running_on,
317+
updated_at = NOW() AT TIME ZONE 'UTC'
318+
WHERE sp_id = _sp_id;
319+
END IF;
320+
321+
RETURN _priv_key;
322+
END;
323+
$$ LANGUAGE plpgsql;
324+
275325
-- Add host column to allow local file based
276326
-- piece park
277327
ALTER TABLE parked_piece_refs
@@ -299,9 +349,6 @@ CREATE TABLE market_legacy_deals (
299349
publish_cid TEXT NOT NULL,
300350
chain_deal_id BIGINT NOT NULL,
301351

302-
piece_cid TEXT NOT NULL,
303-
piece_size BIGINT NOT NULL,
304-
305352
fast_retrieval BOOLEAN NOT NULL,
306353

307354
created_at TIMESTAMPTZ NOT NULL,

itests/alertnow_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func TestAlertNow(t *testing.T) {
2222
// Create dependencies
2323
sharedITestID := harmonydb.ITestNewID()
2424
db, err := harmonydb.NewFromConfigWithITestID(t, sharedITestID)
25-
2625
require.NoError(t, err)
2726

2827
an := alertmanager.NewAlertNow(db, "alertNowMachine")

0 commit comments

Comments
 (0)