feat(chainwatch): track message size in bytes

This commit is contained in:
Mike Greenberg 2020-08-07 14:25:35 -04:00
parent 4bf932a4d7
commit 4ed968b79c

View File

@ -28,6 +28,7 @@ create table if not exists messages
primary key, primary key,
"from" text not null, "from" text not null,
"to" text not null, "to" text not null,
size_bytes bigint not null,
nonce bigint not null, nonce bigint not null,
value text not null, value text not null,
gas_fee_cap text not null, gas_fee_cap text not null,
@ -220,16 +221,22 @@ create temp table msgs (like messages excluding constraints) on commit drop;
return xerrors.Errorf("prep temp: %w", err) return xerrors.Errorf("prep temp: %w", err)
} }
stmt, err := tx.Prepare(`copy msgs (cid, "from", "to", nonce, "value", gas_premium, gas_fee_cap, gas_limit, method, params) from stdin `) stmt, err := tx.Prepare(`copy msgs (cid, "from", "to", size_bytes, nonce, "value", gas_premium, gas_fee_cap, gas_limit, method, params) from stdin `)
if err != nil { if err != nil {
return err return err
} }
for c, m := range msgs { for c, m := range msgs {
var msgBytes int
if b, err := m.Serialize(); err == nil {
msgBytes = len(b)
}
if _, err := stmt.Exec( if _, err := stmt.Exec(
c.String(), c.String(),
m.From.String(), m.From.String(),
m.To.String(), m.To.String(),
msgBytes,
m.Nonce, m.Nonce,
m.Value.String(), m.Value.String(),
m.GasPremium.String(), m.GasPremium.String(),