Skip to content

Commit

Permalink
fix: actor info page issues (#372)
Browse files Browse the repository at this point in the history
* fix actor info page issues

* adjust fonts

* fix QAp calculation

* fix lint err
  • Loading branch information
LexLuthr authored Jan 24, 2025
1 parent 2347010 commit fb8ca64
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 44 deletions.
13 changes: 11 additions & 2 deletions web/api/webrpc/actor_charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,18 @@ func (a *WebRPC) ActorCharts(ctx context.Context, maddr address.Address) (*Secto

// Accumulate data
sb.Count++
sb.QAP = big.Add(sb.QAP, sector.VerifiedDealWeight)
rdw := big.Add(sector.DealWeight, sector.VerifiedDealWeight)

if sector.DealWeight.Equals(abi.NewStoragePower(0)) {
weight := big.Zero()
if sector.DealWeight.GreaterThan(abi.NewStoragePower(0)) {
weight = big.Div(rdw, big.NewInt(int64(sector.Expiration-sector.PowerBaseEpoch)))
}
if sector.VerifiedDealWeight.GreaterThan(abi.NewStoragePower(0)) {
weight = big.Div(big.Mul(sector.VerifiedDealWeight, big.NewInt(verifiedPowerGainMul)), big.NewInt(int64(sector.Expiration-sector.PowerBaseEpoch)))
}
sb.QAP = big.Add(sb.QAP, weight)

if sector.DealWeight.Equals(abi.NewStoragePower(0)) && sector.VerifiedDealWeight.Equals(abi.NewStoragePower(0)) {
sbc, ok := bucketsMapCC[bucket]
if !ok {
sbc = &SectorBucket{
Expand Down
16 changes: 14 additions & 2 deletions web/api/webrpc/actor_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"sync"

"github.com/multiformats/go-multiaddr"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -138,7 +139,14 @@ func (a *WebRPC) ActorInfo(ctx context.Context, ActorIDstr string) (*ActorDetail

var addresses []string
for _, addr := range info.Multiaddrs {
addresses = append(addresses, string(addr))
madr, err := multiaddr.NewMultiaddrBytes(addr)
if err != nil {
log.Errorf("parsing multiaddr: %w", err)
}
if madr == nil {
continue
}
addresses = append(addresses, madr.String())
}

peerID := ""
Expand Down Expand Up @@ -182,7 +190,7 @@ func (a *WebRPC) ActorInfo(ctx context.Context, ActorIDstr string) (*ActorDetail
processedAddrs := make(map[address.Address]struct{})

var wallets []WalletInfo
var mu sync.Mutex
var akm, bcm, mu sync.Mutex

// Use errgroup for error handling with goroutines
g, ctx := errgroup.WithContext(ctx)
Expand All @@ -196,7 +204,9 @@ func (a *WebRPC) ActorInfo(ctx context.Context, ActorIDstr string) (*ActorDetail
if err != nil {
return address.Undef, err
}
akm.Lock()
accountKeyMap[addr] = ak
akm.Unlock()
return ak, nil
}

Expand All @@ -208,7 +218,9 @@ func (a *WebRPC) ActorInfo(ctx context.Context, ActorIDstr string) (*ActorDetail
if err != nil {
return big.Int{}, err
}
bcm.Lock()
balanceCache[addr] = bal
bcm.Unlock()
return bal, nil
}

Expand Down
123 changes: 83 additions & 40 deletions web/static/pages/actor/actor-detail.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { LitElement, html, css } from 'https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js';
import '/actor-summary.mjs'; // <sector-expirations>
import RPCCall from '/lib/jsonrpc.mjs';
// // Import the main Chart.js UMD bundle as an ES module
// import Chart from 'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.js';
// // Import the datalabels plugin
// import ChartDataLabels from 'https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.2.0/dist/chartjs-plugin-datalabels.js';
//
// // Register the plugin with Chart.js (important!)
// Chart.register(ChartDataLabels);

customElements.define('actor-detail', class Actor extends LitElement {
connectedCallback() {
Expand Down Expand Up @@ -67,8 +60,6 @@ customElements.define('actor-detail', class Actor extends LitElement {
this.data = await RPCCall('ActorInfo', [actorID]);
this.requestUpdate();

// TODO SNAP/POREP pipelines

setTimeout(() => this.loadData(), 30000);
this.requestUpdate();
} catch (error) {
Expand All @@ -81,7 +72,7 @@ customElements.define('actor-detail', class Actor extends LitElement {
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8t94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
>
<link
Expand Down Expand Up @@ -111,7 +102,7 @@ customElements.define('actor-detail', class Actor extends LitElement {
</tr>
<tr>
<td>Sector Size:</td>
<td>${this.toHumanBytes(actorInfo.SectorSize)}</td>
<td>${toHumanBytes(actorInfo.SectorSize)}</td>
</tr>
<tr>
<td>Quality Adjusted Power:</td>
Expand Down Expand Up @@ -191,9 +182,9 @@ customElements.define('actor-detail', class Actor extends LitElement {
<tr>
<td><strong>BeneficiaryTerm</strong></td>
<td>
<table class="table table-borderless table-sm">
<table class="table table-dark table-striped table-borderless table-sm">
<tbody>
<tr>
<tr style="color: white">
<td>Quota:</td>
<td>${actorInfo.BeneficiaryTerm.Quota}</td>
</tr>
Expand Down Expand Up @@ -224,7 +215,7 @@ customElements.define('actor-detail', class Actor extends LitElement {
<tr>
<td><strong>PendingBeneficiaryTerm</strong></td>
<td>
<table class="table table-borderless table-sm">
<table class="table table-dark table-borderless table-striped table-sm">
<tbody>
<tr>
<td>NewBeneficiary:</td>
Expand Down Expand Up @@ -299,21 +290,6 @@ customElements.define('actor-detail', class Actor extends LitElement {
`;
}

/**
* Convert a bytes number to a human-readable string (e.g., KB, MB, etc.)
*/
toHumanBytes(bytes) {
if (typeof bytes !== 'number') {
return 'N/A';
}
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB'];
let sizeIndex = 0;
for (; bytes >= 1024 && sizeIndex < sizes.length - 1; sizeIndex++) {
bytes /= 1024;
}
return bytes.toFixed(2) + ' ' + sizes[sizeIndex];
}

/**
* Renders the deadlines as colored boxes
*/
Expand Down Expand Up @@ -474,7 +450,7 @@ class ActorCharts extends LitElement {
data: {
datasets: [
{
label: 'All Sectors (QAP)',
label: 'QAP',
borderColor: 'rgb(255, 205, 86)',
backgroundColor: 'rgba(255, 205, 86, 0.2)',
borderWidth: 1,
Expand All @@ -485,7 +461,7 @@ class ActorCharts extends LitElement {
},
],
},
options: this.createChartOptions('Quality-Adjusted Power (All)', 'QAP', nowEpoch, allQAPData),
options: this.createChartOptions('Quality-Adjusted Power', 'QAP', nowEpoch, allQAPData),
};

if (!this.chartQAP) {
Expand All @@ -502,18 +478,18 @@ class ActorCharts extends LitElement {
// 3) VESTED LOCKED FUNDS CHART (Only All)
// ---------------------------
{
// Also a big-int string; parse to float
// Convert attoFIL to FIL and format for better readability
const allLockedData = this.data.All.map(d => ({
x: d.BucketEpoch,
y: parseFloat(d.VestedLockedFunds), // again, big values => float precision
y: d.VestedLockedFunds / 1e18, // Convert attoFIL to FIL
}));

const lockedConfig = {
type: 'line',
data: {
datasets: [
{
label: 'All Sectors (Locked Funds)',
label: 'Locked Funds',
borderColor: 'rgb(153, 102, 255)',
backgroundColor: 'rgba(153, 102, 255, 0.2)',
borderWidth: 1,
Expand All @@ -524,7 +500,12 @@ class ActorCharts extends LitElement {
},
],
},
options: this.createChartOptions('Vested Locked Funds (All)', 'Locked Funds', nowEpoch, allLockedData),
options: this.createChartOptions(
'Vesting Locked Funds',
'Locked Funds (FIL)',
nowEpoch,
allLockedData
),
};

if (!this.chartVested) {
Expand Down Expand Up @@ -554,17 +535,27 @@ class ActorCharts extends LitElement {
title: {
display: true,
text: chartTitle,
font: {
size: window.innerWidth > 1200 ? 20 : 18, // Adjust font size based on screen width
},
},
tooltip: {
callbacks: {
label: (context) => {
// Convert epoch to 'days' offset from nowEpoch
const epochVal = context.parsed.x;
const daysOffset = Math.round(((epochVal - nowEpoch) * 30) / 86400);
const months = (daysOffset / 30).toFixed(1);
return `${
context.dataset.label
}: ${context.parsed.y}, Days: ${daysOffset} (months: ${months})`;
let value;

if (yTitle === 'QAP') {
value = this.toHumanBytes(context.parsed.y); // For QAP
} else if (yTitle === 'Locked Funds (FIL)') {
value = this.toHumanFIL(context.parsed.y); // For Vesting
} else {
value = context.parsed.y;
}

return `${context.dataset.label}: ${value}, Days: ${daysOffset} (months: ${months})`;
},
},
},
Expand All @@ -576,14 +567,19 @@ class ActorCharts extends LitElement {
title: {
display: true,
text: 'Days in Future',
font: {
size: window.innerWidth > 1200 ? 16 : 14,
},
},
ticks: {
callback: (value) => {
const days = Math.round(((value - nowEpoch) * 30) / 86400);
return days + 'd';
},
font: {
size: window.innerWidth > 1200 ? 14 : 12,
},
},
// compute max from both sets if available
min: nowEpoch,
max: (() => {
const maxAll = allData.length ? allData[allData.length - 1].x : 0;
Expand All @@ -598,13 +594,44 @@ class ActorCharts extends LitElement {
title: {
display: true,
text: yTitle,
font: {
size: window.innerWidth > 1200 ? 14 : 12,
},
},
ticks: {
callback: (value) => {
return yTitle === 'QAP' ? toHumanBytes(value) : value;
},
font: {
size: window.innerWidth > 1200 ? 14 : 12,
},
},
beginAtZero: true,
},
},
};
}

toHumanFIL(value) {
if (typeof value !== 'number' || value === 0) return '0 FIL';

const units = ['nFIL', 'µFIL', 'mFIL', 'FIL'];
let unitIndex = 0;

// Convert value from attoFIL to FIL
value /= 1e18; // Convert attoFIL to FIL

// Adjust to appropriate unit
while (value < 1 && unitIndex < units.length - 1) {
value *= 1000;
unitIndex++;
}

// Format value with 2 decimal places
return value.toFixed(2) + ' ' + units[unitIndex];
}


render() {
return html`
<div class="chart-container">
Expand All @@ -627,3 +654,19 @@ class ActorCharts extends LitElement {

customElements.define('actor-charts', ActorCharts);


/**
* Convert a bytes number to a human-readable string (e.g., KB, MB, etc.)
*/
function toHumanBytes(bytes) {
if (typeof bytes !== 'number') {
return 'N/A';
}
const sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB'];
let sizeIndex = 0;
for (; bytes >= 1024 && sizeIndex < sizes.length - 1; sizeIndex++) {
bytes /= 1024;
}
return bytes.toFixed(2) + ' ' + sizes[sizeIndex];
}

0 comments on commit fb8ca64

Please sign in to comment.