-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add power actor claim extraction
closes #171
- Loading branch information
Showing
12 changed files
with
315 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package power | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-pg/pg/v10" | ||
"go.opentelemetry.io/otel/api/global" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type PowerActorClaim struct { | ||
Height int64 `pg:",pk,notnull,use_zero"` | ||
MinerID string `pg:",pk,notnull"` | ||
StateRoot string `pg:",pk,notnull"` | ||
RawBytePower string `pg:",notnull"` | ||
QualityAdjPower string `pg:",notnull"` | ||
} | ||
|
||
func (p *PowerActorClaim) PersistWithTx(ctx context.Context, tx *pg.Tx) error { | ||
ctx, span := global.Tracer("").Start(ctx, "PowerActorClaim.PersistWithTx") | ||
defer span.End() | ||
if _, err := tx.ModelContext(ctx, p). | ||
OnConflict("do nothing"). | ||
Insert(); err != nil { | ||
return xerrors.Errorf("persisting power actors claim: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
type PowerActorClaimList []*PowerActorClaim | ||
|
||
func (pl PowerActorClaimList) PersistWithTx(ctx context.Context, tx *pg.Tx) error { | ||
ctx, span := global.Tracer("").Start(ctx, "PowerActorClaimList.PersistWithTx") | ||
defer span.End() | ||
if len(pl) == 0 { | ||
return nil | ||
} | ||
if _, err := tx.ModelContext(ctx, &pl). | ||
OnConflict("do nothing"). | ||
Insert(); err != nil { | ||
return xerrors.Errorf("persisting power actor claim list: %w") | ||
} | ||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package power | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-pg/pg/v10" | ||
"go.opentelemetry.io/otel/api/global" | ||
|
||
"github.com/filecoin-project/sentinel-visor/metrics" | ||
) | ||
|
||
type PowerTaskResult struct { | ||
ChainPowerModel *ChainPower | ||
ClaimStateModel PowerActorClaimList | ||
} | ||
|
||
func (p *PowerTaskResult) PersistWithTx(ctx context.Context, tx *pg.Tx) error { | ||
if p.ChainPowerModel != nil { | ||
if err := p.ChainPowerModel.PersistWithTx(ctx, tx); err != nil { | ||
return err | ||
} | ||
} | ||
if p.ClaimStateModel != nil { | ||
if err := p.ClaimStateModel.PersistWithTx(ctx, tx); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (p *PowerTaskResult) Persist(ctx context.Context, db *pg.DB) error { | ||
ctx, span := global.Tracer("").Start(ctx, "PowerTaskResult.Persist") | ||
defer span.End() | ||
|
||
stop := metrics.Timer(ctx, metrics.PersistDuration) | ||
defer stop() | ||
|
||
return db.RunInTransaction(ctx, func(tx *pg.Tx) error { | ||
return p.PersistWithTx(ctx, tx) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/go-pg/migrations/v8" | ||
) | ||
|
||
// Schema version 16 adds power actor claims table | ||
|
||
func init() { | ||
up := batch(` | ||
CREATE TABLE IF NOT EXISTS "power_actor_claims" ( | ||
"height" bigint not null, | ||
"miner_id" text not null, | ||
"state_root" text not null, | ||
"raw_byte_power" text not null, | ||
"quality_adj_power" text not null, | ||
PRIMARY KEY ("height", "miner_id", "state_root") | ||
); | ||
`) | ||
|
||
down := batch(` | ||
DROP TABLE IF EXISTS public.power_actor_claims; | ||
`) | ||
|
||
migrations.MustRegisterTx(up, down) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.