-
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 a new table, chain_economics_v2, for nv23 (#1311)
* feat: add a new table, chain_economics_v2, for nv23
- Loading branch information
Showing
13 changed files
with
159 additions
and
23 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
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
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,49 @@ | ||
package chain | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opencensus.io/tag" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
|
||
"github.com/filecoin-project/lily/metrics" | ||
"github.com/filecoin-project/lily/model" | ||
) | ||
|
||
type ChainEconomicsV2 struct { | ||
tableName struct{} `pg:"chain_economics_v2"` // nolint: structcheck | ||
Height int64 `pg:",pk,notnull,use_zero"` | ||
ParentStateRoot string `pg:",pk,notnull"` | ||
CirculatingFilV2 string `pg:"type:numeric,notnull"` | ||
VestedFil string `pg:"type:numeric,notnull"` | ||
MinedFil string `pg:"type:numeric,notnull"` | ||
BurntFil string `pg:"type:numeric,notnull"` | ||
LockedFilV2 string `pg:"type:numeric,notnull"` | ||
FilReserveDisbursed string `pg:"type:numeric,notnull"` | ||
} | ||
|
||
func (c *ChainEconomicsV2) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error { | ||
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "chain_economics")) | ||
|
||
metrics.RecordCount(ctx, metrics.PersistModel, 1) | ||
return s.PersistModel(ctx, c) | ||
} | ||
|
||
type ChainEconomicsV2List []*ChainEconomicsV2 | ||
|
||
func (l ChainEconomicsV2List) Persist(ctx context.Context, s model.StorageBatch, _ model.Version) error { | ||
if len(l) == 0 { | ||
return nil | ||
} | ||
ctx, span := otel.Tracer("").Start(ctx, "ChainEconomicsV2List.Persist") | ||
if span.IsRecording() { | ||
span.SetAttributes(attribute.Int("count", len(l))) | ||
} | ||
defer span.End() | ||
|
||
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "chain_economics_v2")) | ||
|
||
metrics.RecordCount(ctx, metrics.PersistModel, len(l)) | ||
return s.PersistModel(ctx, l) | ||
} |
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,24 @@ | ||
package v1 | ||
|
||
func init() { | ||
patches.Register( | ||
40, | ||
` | ||
ALTER TABLE {{ .SchemaName | default "public"}}.chain_economics DROP COLUMN IF EXISTS locked_fil_v2; | ||
CREATE TABLE {{ .SchemaName | default "public"}}.chain_economics_v2 ( | ||
height bigint NOT NULL, | ||
parent_state_root text NOT NULL, | ||
circulating_fil_v2 numeric NOT NULL, | ||
vested_fil numeric NOT NULL, | ||
mined_fil numeric NOT NULL, | ||
burnt_fil numeric NOT NULL, | ||
locked_fil_v2 numeric NOT NULL, | ||
fil_reserve_disbursed numeric NOT NULL | ||
); | ||
ALTER TABLE ONLY {{ .SchemaName | default "public"}}.chain_economics_v2 ADD CONSTRAINT chain_economics_v2_pk PRIMARY KEY (height, parent_state_root); | ||
CREATE INDEX IF NOT EXISTS chain_economics_v2_height_idx ON {{ .SchemaName | default "public"}}.chain_economics_v2 USING btree (height DESC); | ||
`, | ||
) | ||
} |
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,48 @@ | ||
package chaineconomics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
|
||
"github.com/filecoin-project/lily/lens/util" | ||
chainmodel "github.com/filecoin-project/lily/model/chain" | ||
|
||
"github.com/filecoin-project/lotus/chain/types" | ||
|
||
network2 "github.com/filecoin-project/go-state-types/network" | ||
) | ||
|
||
func ExtractChainEconomicsV2Model(ctx context.Context, node ChainEconomicsLens, ts *types.TipSet) (*chainmodel.ChainEconomicsV2, error) { | ||
currentNetworkVersion := util.DefaultNetwork.Version(ctx, ts.Height()) | ||
if currentNetworkVersion < network2.Version23 { | ||
log.Infof("The chain_economics_v2 will be supported in nv23. Current network version is %v", currentNetworkVersion) | ||
return nil, nil | ||
} | ||
|
||
ctx, span := otel.Tracer("").Start(ctx, "ExtractChainEconomicsV2") | ||
if span.IsRecording() { | ||
span.SetAttributes(attribute.String("tipset", ts.String()), attribute.Int64("height", int64(ts.Height()))) | ||
} | ||
defer span.End() | ||
|
||
supply, err := node.CirculatingSupply(ctx, ts) | ||
if err != nil { | ||
return nil, fmt.Errorf("get circulating supply: %w", err) | ||
} | ||
|
||
chainEconomicV2 := &chainmodel.ChainEconomicsV2{ | ||
Height: int64(ts.Height()), | ||
ParentStateRoot: ts.ParentState().String(), | ||
VestedFil: supply.FilVested.String(), | ||
MinedFil: supply.FilMined.String(), | ||
BurntFil: supply.FilBurnt.String(), | ||
LockedFilV2: supply.FilLocked.String(), | ||
CirculatingFilV2: supply.FilCirculating.String(), | ||
FilReserveDisbursed: supply.FilReserveDisbursed.String(), | ||
} | ||
|
||
return chainEconomicV2, 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