mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-30 19:11:59 +03:00
Merge pull request #6695 from urbit/pkova/delete-nonsense
%base: delete /app/gaze and /ted/naive-csv
This commit is contained in:
commit
8f5d29fb73
@ -1,618 +0,0 @@
|
||||
:: gaze: azimuth statistics
|
||||
::
|
||||
:: general flow:
|
||||
:: - receive events
|
||||
:: - process events whose timestamp is known
|
||||
:: - request timestamps for unknown block numbers (if not already running)
|
||||
:: - receive timestamps, process events
|
||||
::
|
||||
/- eth-watcher
|
||||
/+ *ethereum, *azimuth, default-agent, verb
|
||||
::
|
||||
=> |%
|
||||
+$ state-0
|
||||
$: %0
|
||||
:: qued: event logs waiting on block timestamp, oldest first
|
||||
:: time: timstamps of block numbers
|
||||
:: seen: events sorted by timestamp, newest first
|
||||
:: days: stats by day, newest first
|
||||
::
|
||||
running=(unit @ta)
|
||||
qued=loglist
|
||||
time=(map @ud @da)
|
||||
seen=(list [wen=@da wat=event])
|
||||
days=(list [day=@da sat=stats])
|
||||
==
|
||||
::
|
||||
+$ loglist loglist:eth-watcher
|
||||
+$ event
|
||||
$% [%azimuth who=ship dif=diff-point]
|
||||
[%invite by=ship of=ship gift=ship to=address]
|
||||
==
|
||||
::
|
||||
+$ stats
|
||||
$: spawned=(list @p)
|
||||
activated=(list @p)
|
||||
transfer-p=(list @p)
|
||||
transferred=(list @p)
|
||||
configured=(list @p)
|
||||
breached=(list @p)
|
||||
request=(list @p)
|
||||
sponsor=(list @p)
|
||||
management-p=(list @p)
|
||||
voting-p=(list @p)
|
||||
spawn-p=(list @p)
|
||||
invites-senders=(list @p)
|
||||
==
|
||||
::
|
||||
+$ card card:agent:gall
|
||||
::
|
||||
++ node-url 'http://eth-mainnet.urbit.org:8545'
|
||||
++ refresh-rate ~h1
|
||||
++ timeout-time ~h2
|
||||
--
|
||||
::
|
||||
=| state-0
|
||||
=* state -
|
||||
::
|
||||
%+ verb |
|
||||
^- agent:gall
|
||||
=<
|
||||
|_ =bowl:gall
|
||||
+* this .
|
||||
do ~(. +> bowl)
|
||||
def ~(. (default-agent this %|) bowl)
|
||||
bec byk.bowl(r da+now.bowl)
|
||||
::
|
||||
++ on-init
|
||||
^- (quip card _this)
|
||||
[setup-cards:do this]
|
||||
::
|
||||
++ on-save !>(state)
|
||||
++ on-load
|
||||
|= old=vase
|
||||
^- (quip card _this)
|
||||
[~ this(state !<(state-0 old))]
|
||||
::
|
||||
++ on-poke
|
||||
|= [=mark =vase]
|
||||
^- (quip card _this)
|
||||
?> ?=(%noun mark)
|
||||
=/ =noun !<(noun vase)
|
||||
|- ^- [cards=(list card) =_this]
|
||||
?+ noun ~|([dap.bowl %unknown-poke noun] !!)
|
||||
%reconnect
|
||||
:_ this
|
||||
:~ leave-eth-watcher:do
|
||||
watch-eth-watcher:do
|
||||
==
|
||||
::
|
||||
%reload
|
||||
:- cards:$(noun %reconnect)
|
||||
this(qued ~, seen ~, days ~)
|
||||
::
|
||||
%rewatch
|
||||
:_ this:$(noun %reset)
|
||||
:~ leave-eth-watcher:do
|
||||
clear-eth-watcher:do
|
||||
setup-eth-watcher:do
|
||||
await-eth-watcher:do
|
||||
==
|
||||
::
|
||||
%export
|
||||
[export:do this]
|
||||
::
|
||||
%debug
|
||||
~& latest=(turn (scag 5 seen) head)
|
||||
~& oldest=(turn (slag (sub (max 5 (lent seen)) 5) seen) head)
|
||||
~& :- 'order is'
|
||||
=- ?:(sane 'sane' 'insane')
|
||||
%+ roll seen
|
||||
|= [[this=@da *] last=@da sane=?]
|
||||
:- this
|
||||
?: =(*@da last) &
|
||||
(lte this last)
|
||||
~& time=~(wyt by time)
|
||||
~& qued=(lent qued)
|
||||
~& days=(lent days)
|
||||
[~ this]
|
||||
==
|
||||
::
|
||||
++ on-agent
|
||||
|= [=wire =sign:agent:gall]
|
||||
^- (quip card _this)
|
||||
?+ -.sign (on-agent:def wire sign)
|
||||
%kick
|
||||
?. =(/watcher wire) [~ this]
|
||||
[[watch-eth-watcher:do]~ this]
|
||||
::
|
||||
%fact
|
||||
?+ wire (on-agent:def wire sign)
|
||||
[%watcher ~]
|
||||
?. ?=(%eth-watcher-diff p.cage.sign)
|
||||
(on-agent:def wire sign)
|
||||
=^ cards state
|
||||
%- handle-eth-watcher-diff:do
|
||||
!<(diff:eth-watcher q.cage.sign)
|
||||
[cards this]
|
||||
::
|
||||
[%timestamps @ ~]
|
||||
?+ p.cage.sign (on-agent:def wire sign)
|
||||
%thread-fail
|
||||
=+ !<([=term =tang] q.cage.sign)
|
||||
=/ =tank leaf+"{(trip dap.bowl)} thread failed; will retry"
|
||||
%- (slog tank leaf+<term> tang)
|
||||
=^ cards state
|
||||
request-timestamps:do
|
||||
[cards this]
|
||||
::
|
||||
%thread-done
|
||||
=^ cards state
|
||||
%- save-timestamps:do
|
||||
!<((list [@ud @da]) q.cage.sign)
|
||||
[cards this]
|
||||
==
|
||||
==
|
||||
==
|
||||
::
|
||||
++ on-arvo
|
||||
|= [=wire =sign-arvo]
|
||||
^- (quip card _this)
|
||||
?+ +<.sign-arvo ~|([dap.bowl %strange-arvo-sign +<.sign-arvo] !!)
|
||||
%wake
|
||||
?: =(/export wire)
|
||||
[[wait-export:do export:do] this]
|
||||
?: =(/watch wire)
|
||||
[[watch-eth-watcher:do]~ this]
|
||||
~& [dap.bowl %strange-wake wire]
|
||||
[~ this]
|
||||
==
|
||||
::
|
||||
++ on-peek on-peek:def
|
||||
++ on-watch on-watch:def
|
||||
++ on-leave on-leave:def
|
||||
++ on-fail on-fail:def
|
||||
--
|
||||
::
|
||||
|_ =bowl:gall
|
||||
++ bec byk.bowl(r da+now.bowl)
|
||||
++ setup-cards
|
||||
^- (list card)
|
||||
:~ wait-export
|
||||
setup-eth-watcher
|
||||
:: we punt on subscribing to the eth-watcher for a little while.
|
||||
:: this way we get a %history diff containing all past events,
|
||||
:: instead of so many individual %log diffs that we bail meme.
|
||||
:: (to repro, replace this with `watch-eth-watcher`)
|
||||
::
|
||||
await-eth-watcher
|
||||
==
|
||||
::
|
||||
++ wait
|
||||
|= [=wire =@dr]
|
||||
^- card
|
||||
[%pass wire %arvo %b %wait (add now.bowl dr)]
|
||||
::
|
||||
++ wait-export (wait /export refresh-rate)
|
||||
::
|
||||
++ to-eth-watcher
|
||||
|= [=wire =task:agent:gall]
|
||||
^- card
|
||||
[%pass wire %agent [our.bowl %eth-watcher] task]
|
||||
::
|
||||
++ setup-eth-watcher
|
||||
%+ to-eth-watcher /setup
|
||||
:+ %poke %eth-watcher-poke
|
||||
!> ^- poke:eth-watcher
|
||||
:+ %watch /[dap.bowl]
|
||||
:* node-url
|
||||
|
|
||||
refresh-rate
|
||||
timeout-time
|
||||
public:mainnet-contracts
|
||||
~
|
||||
~[azimuth delegated-sending]:mainnet-contracts
|
||||
~
|
||||
~
|
||||
==
|
||||
::
|
||||
:: see also comment in +setup-cards
|
||||
++ await-eth-watcher (wait /watch ~m30)
|
||||
::
|
||||
++ watch-eth-watcher
|
||||
%+ to-eth-watcher /watcher
|
||||
[%watch /logs/[dap.bowl]]
|
||||
::
|
||||
++ leave-eth-watcher
|
||||
%+ to-eth-watcher /watcher
|
||||
[%leave ~]
|
||||
::
|
||||
++ clear-eth-watcher
|
||||
%+ to-eth-watcher /clear
|
||||
:+ %poke %eth-watcher-poke
|
||||
!> ^- poke:eth-watcher
|
||||
[%clear /logs/[dap.bowl]]
|
||||
::
|
||||
++ poke-spider
|
||||
|= [=wire =cage]
|
||||
^- card
|
||||
[%pass wire %agent [our.bowl %spider] %poke cage]
|
||||
::
|
||||
++ watch-spider
|
||||
|= [=wire =sub=path]
|
||||
^- card
|
||||
[%pass wire %agent [our.bowl %spider] %watch sub-path]
|
||||
::
|
||||
:: +handle-eth-watcher-diff: process new logs, clear state on rollback
|
||||
::
|
||||
:: processes logs for which we know the timestamp
|
||||
:: adds timestamp-less logs to queue
|
||||
::
|
||||
++ handle-eth-watcher-diff
|
||||
|= =diff:eth-watcher
|
||||
^- (quip card _state)
|
||||
=^ logs state
|
||||
^- [loglist _state]
|
||||
?- -.diff
|
||||
%history ~& [%got-history (lent loglist.diff)]
|
||||
[loglist.diff state(qued ~, seen ~)]
|
||||
%logs ~& %got-log
|
||||
[loglist.diff state]
|
||||
%disavow ~& %disavow-unimplemented
|
||||
[~ state]
|
||||
==
|
||||
%- process-logs
|
||||
%+ skip logs
|
||||
|= =event-log:rpc
|
||||
%- is-lockup-block
|
||||
block-number:(need mined.event-log)
|
||||
::
|
||||
:: +is-lockup-block: whether the block contains lockup/ignorable transactions
|
||||
::
|
||||
:: this is the stupid dumb equivalent to actually identifying lockup
|
||||
:: transactions procedurally, which is still in git history, but didn't
|
||||
:: work quite right for unidentified reasons
|
||||
::
|
||||
++ is-lockup-block
|
||||
|= num=@ud
|
||||
^- ?
|
||||
%+ roll
|
||||
^- (list [@ud @ud])
|
||||
:~ [7.050.978 7.051.038]
|
||||
==
|
||||
|= [[start=@ud end=@ud] in=_|]
|
||||
?: in &
|
||||
&((gte num start) (lte num end))
|
||||
::
|
||||
:: +request-timestamps: request block timestamps for the logs as necessary
|
||||
::
|
||||
:: will come back as a thread result
|
||||
::
|
||||
++ request-timestamps
|
||||
^- (quip card _state)
|
||||
?~ qued [~ state]
|
||||
?^ running [~ state]
|
||||
=/ tid=@ta
|
||||
%+ scot %ta
|
||||
:((cury cat 3) dap.bowl '_' (scot %uv eny.bowl))
|
||||
:_ state(running `tid)
|
||||
:~ (watch-spider /timestamps/[tid] /thread-result/[tid])
|
||||
::
|
||||
%+ poke-spider /timestamps/[tid]
|
||||
:- %spider-start
|
||||
=- !>([~ `tid bec %eth-get-timestamps -])
|
||||
!> ^- [@t (list @ud)]
|
||||
:- node-url
|
||||
=- ~(tap in -)
|
||||
%- ~(gas in *(set @ud))
|
||||
^- (list @ud)
|
||||
%+ turn qued
|
||||
|= log=event-log:rpc
|
||||
block-number:(need mined.log)
|
||||
==
|
||||
::
|
||||
:: +save-timestamps: store timestamps into state
|
||||
::
|
||||
++ save-timestamps
|
||||
|= timestamps=(list [@ud @da])
|
||||
^- (quip card _state)
|
||||
=. time (~(gas by time) timestamps)
|
||||
=. running ~
|
||||
(process-logs ~)
|
||||
::
|
||||
:: +process-logs: handle new incoming logs
|
||||
::
|
||||
++ process-logs
|
||||
|= new=loglist :: oldest first
|
||||
^- (quip card _state)
|
||||
=. qued (weld qued new)
|
||||
?~ qued [~ state]
|
||||
=- %_ request-timestamps
|
||||
qued (flop rest) :: oldest first
|
||||
seen (weld logs seen) :: newest first
|
||||
days (count-events (flop logs)) :: oldest first
|
||||
==
|
||||
%+ roll `loglist`qued
|
||||
|= [log=event-log:rpc [rest=loglist logs=(list [wen=@da wat=event])]]
|
||||
:: to ensure logs are processed in sane order,
|
||||
:: stop processing as soon as we skipped one
|
||||
::
|
||||
?^ rest [[log rest] logs]
|
||||
=/ tim=(unit @da)
|
||||
%- ~(get by time)
|
||||
block-number:(need mined.log)
|
||||
?~ tim [[log rest] logs]
|
||||
:- rest
|
||||
=+ ven=(event-log-to-event log)
|
||||
?~ ven logs
|
||||
[[u.tim u.ven] logs]
|
||||
::
|
||||
:: +event-log-to-event: turn raw log into gaze noun
|
||||
::
|
||||
++ event-log-to-event
|
||||
|= log=event-log:rpc
|
||||
^- (unit event)
|
||||
?: =(azimuth:mainnet-contracts address.log)
|
||||
=+ (event-log-to-point-diff log)
|
||||
?~ - ~
|
||||
`azimuth+u
|
||||
?: =(delegated-sending:mainnet-contracts address.log)
|
||||
?. .= i.topics.log
|
||||
0x4763.8e3c.ddee.2204.81e4.c3f9.183d.639c.
|
||||
0efe.a7f0.5fcd.2df4.1888.5572.9f71.5419
|
||||
~
|
||||
=/ [of=@ pool=@]
|
||||
~| t.topics.log
|
||||
%+ decode-topics:abi:ethereum t.topics.log
|
||||
~[%uint %uint]
|
||||
=/ [by=@ gift=@ to=@]
|
||||
~| data.log
|
||||
%+ decode-topics:abi:ethereum
|
||||
%+ rash data.log
|
||||
=- ;~(pfix (jest '0x') -)
|
||||
%+ stun [3 3]
|
||||
(bass 16 (stun [64 64] hit))
|
||||
~[%uint %uint %address]
|
||||
`invite+[by of gift to]
|
||||
~
|
||||
::
|
||||
:: +count-events: add events to the daily stats
|
||||
::
|
||||
++ count-events
|
||||
|= logs=_seen :: oldest first
|
||||
^+ days
|
||||
=/ head=[day=@da sat=stats]
|
||||
?^ days i.days
|
||||
*[@da stats]
|
||||
=+ tail=?~(days ~ t.days)
|
||||
|-
|
||||
:: when done, store updated head, but only if it's set
|
||||
::
|
||||
?~ logs
|
||||
?: =(*[@da stats] head) tail
|
||||
[head tail]
|
||||
=* log i.logs
|
||||
:: calculate day for current event, set head if unset
|
||||
::
|
||||
=/ day=@da
|
||||
(sub wen.log (mod wen.log ~d1))
|
||||
=? day.head =(*@da day.head) day
|
||||
:: same day as head, so add to it
|
||||
::
|
||||
?: =(day day.head)
|
||||
%_ $
|
||||
sat.head (count-event wat.log sat.head)
|
||||
logs t.logs
|
||||
==
|
||||
~| [%weird-new-day old=day.head new=day]
|
||||
?> (gth day day.head)
|
||||
:: newer day than head of days, so start new head
|
||||
::
|
||||
%_ $
|
||||
tail [head tail]
|
||||
head [day *stats]
|
||||
==
|
||||
::
|
||||
:: +count-event: add event to the stats, if it's relevant
|
||||
::
|
||||
++ count-event
|
||||
|= [eve=event sat=stats]
|
||||
^- stats
|
||||
?- -.eve
|
||||
%invite sat(invites-senders [by.eve invites-senders.sat])
|
||||
::
|
||||
%azimuth
|
||||
?+ -.dif.eve sat
|
||||
%spawned sat(spawned [who.dif.eve spawned.sat])
|
||||
%activated sat(activated [who.eve activated.sat])
|
||||
%transfer-proxy ?: =(0x0 new.dif.eve) sat
|
||||
sat(transfer-p [who.eve transfer-p.sat])
|
||||
%owner sat(transferred [who.eve transferred.sat])
|
||||
%keys sat(configured [who.eve configured.sat])
|
||||
%continuity sat(breached [who.eve breached.sat])
|
||||
%escape ?~ new.dif.eve sat
|
||||
sat(request [who.eve request.sat])
|
||||
%sponsor ?. has.new.dif.eve sat
|
||||
sat(sponsor [who.eve sponsor.sat])
|
||||
%management-proxy sat(management-p [who.eve management-p.sat])
|
||||
%voting-proxy sat(voting-p [who.eve voting-p.sat])
|
||||
%spawn-proxy sat(spawn-p [who.eve spawn-p.sat])
|
||||
==
|
||||
==
|
||||
::
|
||||
::
|
||||
:: +export: periodically export data
|
||||
::
|
||||
++ export
|
||||
^- (list card)
|
||||
:~ (export-move %days (export-days days))
|
||||
(export-move %months (export-months days))
|
||||
(export-move %events export-raw)
|
||||
==
|
||||
::
|
||||
:: +export-move: %info move to write exported .txt
|
||||
::
|
||||
++ export-move
|
||||
|= [nom=@t dat=(list @t)]
|
||||
^- card
|
||||
=- [%pass /export/[nom] %arvo %c %info -]
|
||||
%+ foal:space:userlib
|
||||
/(scot %p our.bowl)/base/(scot %da now.bowl)/gaze-exports/[nom]/txt
|
||||
[%txt !>(dat)]
|
||||
::
|
||||
:: +peek-x: accept gall scry
|
||||
::
|
||||
:: %/days/txt: per day, digest stats
|
||||
:: %/months/txt: per month, digest stats
|
||||
:: %/raw/txt: all observed events
|
||||
::
|
||||
++ peek-x ::TODO
|
||||
|= pax=path
|
||||
^- (unit (unit (pair mark *)))
|
||||
?~ pax ~
|
||||
?: =(%days i.pax)
|
||||
:^ ~ ~ %txt
|
||||
(export-days days)
|
||||
?: =(%months i.pax)
|
||||
:^ ~ ~ %txt
|
||||
(export-months days)
|
||||
?: =(%raw i.pax)
|
||||
``txt+export-raw
|
||||
~
|
||||
::
|
||||
:: +export-months: generate a csv of stats per month
|
||||
::
|
||||
++ export-months
|
||||
|= =_days
|
||||
%- export-days
|
||||
^+ days
|
||||
%+ roll (flop days)
|
||||
|= [[day=@da sat=stats] mos=(list [mod=@da sat=stats])]
|
||||
^+ mos
|
||||
=/ mod=@da
|
||||
%- year
|
||||
=+ (yore day)
|
||||
-(d.t 1)
|
||||
?~ mos [mod sat]~
|
||||
?: !=(mod mod.i.mos)
|
||||
[[mod sat] mos]
|
||||
:_ t.mos
|
||||
:- mod
|
||||
::TODO this is hideous. can we make a wet gate do this?
|
||||
:* (weld spawned.sat spawned.sat.i.mos)
|
||||
(weld activated.sat activated.sat.i.mos)
|
||||
(weld transfer-p.sat transfer-p.sat.i.mos)
|
||||
(weld transferred.sat transferred.sat.i.mos)
|
||||
(weld configured.sat configured.sat.i.mos)
|
||||
(weld breached.sat breached.sat.i.mos)
|
||||
(weld request.sat request.sat.i.mos)
|
||||
(weld sponsor.sat sponsor.sat.i.mos)
|
||||
(weld management-p.sat management-p.sat.i.mos)
|
||||
(weld voting-p.sat voting-p.sat.i.mos)
|
||||
(weld spawn-p.sat spawn-p.sat.i.mos)
|
||||
(weld invites-senders.sat invites-senders.sat.i.mos)
|
||||
==
|
||||
::
|
||||
:: +export-days: generate a csv of stats per day
|
||||
::
|
||||
++ export-days
|
||||
|= =_days
|
||||
:- %- crip
|
||||
;: weld
|
||||
"date,"
|
||||
"spawned,"
|
||||
"activated,"
|
||||
"transfer proxy,"
|
||||
"transferred,"
|
||||
"transferred (unique),"
|
||||
"configured,"
|
||||
"configured (unique),"
|
||||
"escape request,"
|
||||
"sponsor change,"
|
||||
"invites,"
|
||||
"invites (unique senders)"
|
||||
==
|
||||
|^ ^- (list @t)
|
||||
%+ turn days
|
||||
|= [day=@da stats]
|
||||
%- crip
|
||||
;: weld
|
||||
(scow %da day) ","
|
||||
(count spawned) ","
|
||||
(count activated) ","
|
||||
(count transfer-p) ","
|
||||
(unique transferred) ","
|
||||
(unique configured) ","
|
||||
(count request) ","
|
||||
(count sponsor) ","
|
||||
(unique invites-senders)
|
||||
==
|
||||
::
|
||||
++ count
|
||||
|* l=(list)
|
||||
(num (lent l))
|
||||
::
|
||||
++ unique
|
||||
|* l=(list)
|
||||
;: weld
|
||||
(count l)
|
||||
","
|
||||
(num ~(wyt in (~(gas in *(set)) l)))
|
||||
==
|
||||
::
|
||||
++ num (d-co:co 1)
|
||||
--
|
||||
::
|
||||
:: +export-raw: generate a csv of individual transactions
|
||||
::
|
||||
++ export-raw
|
||||
:- %- crip
|
||||
;: weld
|
||||
"date,"
|
||||
"point,"
|
||||
"event,"
|
||||
"field 1,field2,field3"
|
||||
==
|
||||
|^ ^- (list @t)
|
||||
%+ turn seen
|
||||
:: (cork tail event-to-row crip)
|
||||
|= [wen=@da =event]
|
||||
(crip "{(scow %da wen)},{(event-to-row event)}")
|
||||
::
|
||||
++ event-to-row
|
||||
|= =event
|
||||
?- -.event
|
||||
%azimuth (point-diff-to-row +.event)
|
||||
%invite (invite-to-row +.event)
|
||||
==
|
||||
::
|
||||
++ point-diff-to-row
|
||||
|= [who=ship dif=diff-point]
|
||||
^- tape
|
||||
%+ weld "{(pon who)},"
|
||||
?- -.dif
|
||||
%full "full,"
|
||||
%owner "owner,{(adr new.dif)}"
|
||||
%activated "activated,"
|
||||
%spawned "spawned,{(pon who.dif)}"
|
||||
%keys "keys,{(num life.dif)}"
|
||||
%continuity "breached,{(num new.dif)}"
|
||||
%sponsor "sponsor,{(spo has.new.dif)},{(pon who.new.dif)}"
|
||||
%escape "escape-req,{(req new.dif)}"
|
||||
%management-proxy "management-p,{(adr new.dif)}"
|
||||
%voting-proxy "voting-p,{(adr new.dif)}"
|
||||
%spawn-proxy "spawn-p,{(adr new.dif)}"
|
||||
%transfer-proxy "transfer-p,{(adr new.dif)}"
|
||||
==
|
||||
::
|
||||
++ invite-to-row
|
||||
|= [by=ship of=ship ship to=address]
|
||||
"{(pon by)},invite,{(pon of)},{(adr to)}"
|
||||
::
|
||||
++ num (d-co:co 1)
|
||||
++ pon (cury scow %p)
|
||||
++ adr |=(a=@ ['0' 'x' ((x-co:co (mul 2 20)) a)])
|
||||
++ spo |=(h=? ?:(h "escaped to" "detached from"))
|
||||
++ req |=(r=(unit @p) ?~(r "canceled" (pon u.r)))
|
||||
--
|
||||
--
|
@ -1,390 +0,0 @@
|
||||
:: naive-csv: produces csv file containing L2 transaction data
|
||||
::
|
||||
:: takes in the network to use and the ethereum node url to grab data from.
|
||||
:: it starts with the azimuth snapshot and scries the logs from %azimuth.
|
||||
:: it then produces a csv file containing the following data on L2
|
||||
:: transactions:
|
||||
::
|
||||
:: - block number
|
||||
:: - timestamp
|
||||
:: - roller address
|
||||
:: - roll hash
|
||||
:: - tx hash
|
||||
:: - sending ship
|
||||
:: - sending proxy
|
||||
:: - nonce
|
||||
:: - gas price
|
||||
:: - length of input data
|
||||
:: - success or failure
|
||||
:: - function name
|
||||
:: - spawning ship (^sein:title)
|
||||
::
|
||||
:: A lot of the data-scrounging here is stuff that %roller already keeps track
|
||||
:: of. We could just scry it from there, but then this thread needs to be run
|
||||
:: on the roller ship. So we rebuild the list of historical transactions
|
||||
:: ourselves so that this can run from any ship.
|
||||
::
|
||||
/- dice,
|
||||
spider
|
||||
::
|
||||
/+ dice,
|
||||
ethereum,
|
||||
ethio,
|
||||
naive,
|
||||
naive-tx=naive-transactions,
|
||||
*strandio
|
||||
::
|
||||
=, strand=strand:spider
|
||||
=, jael
|
||||
::
|
||||
^- thread:spider
|
||||
=< process-logs
|
||||
=>
|
||||
|%
|
||||
:: imported logs is cast as $events
|
||||
+$ events (list event-log:rpc:ethereum)
|
||||
+$ address address:naive :: @ux
|
||||
+$ keccak @ux :: used for transaction and roll hashes
|
||||
+$ blocknum number:block :: @udblocknumber
|
||||
+$ net net:dice :: ?(%mainnet %goerli %local %default)
|
||||
+$ roll-dat :: all data required for each roll
|
||||
[[gas=@ud sender=address] =effects:naive]
|
||||
+$ block-dat :: all data required for each block
|
||||
[timestamp=@da rolls=(map keccak roll-dat)]
|
||||
+$ block-map (map blocknum block-dat)
|
||||
+$ rolls-map (map blocknum (map keccak effects:naive))
|
||||
::
|
||||
+$ action
|
||||
$? %transfer-point
|
||||
%spawn
|
||||
%configure-keys
|
||||
%escape
|
||||
%cancel-escape
|
||||
%adopt
|
||||
%reject
|
||||
%detach
|
||||
%set-management-proxy
|
||||
%set-spawn-proxy
|
||||
%set-transfer-proxy
|
||||
==
|
||||
::
|
||||
+$ tx-data
|
||||
$: =blocknum
|
||||
timestamp=@da
|
||||
roller=address
|
||||
roll-hash=keccak
|
||||
tx-hash=keccak
|
||||
sender=ship
|
||||
proxy=proxy:naive
|
||||
nonce=nonce:naive
|
||||
gas=@ud
|
||||
length=@ux
|
||||
suc=?
|
||||
=action
|
||||
parent=ship
|
||||
==
|
||||
--
|
||||
::
|
||||
|%
|
||||
:: +process-logs is the main process. it grabs the azimuth snapshop, runs
|
||||
:: +naive on the logs, grabs the timestamps and gas costs for each roll,
|
||||
:: then flattens them into a list of $tx-data and saves them to disk.
|
||||
::
|
||||
++ process-logs
|
||||
|= arg=vase
|
||||
=+ !<([~ =net node-url=@t] arg)
|
||||
=/ pax=path /naive-exports/csv :: data will be saved here
|
||||
=/ m (strand ,vase)
|
||||
^- form:m
|
||||
;< =events bind:m (scry events /gx/azimuth/logs/noun)
|
||||
=/ [naive-contract=address chain-id=@]
|
||||
[naive chain-id]:(get-network:dice net)
|
||||
;< =bowl:spider bind:m get-bowl
|
||||
=/ snap=snap-state:dice
|
||||
.^ snap-state:dice %gx
|
||||
/(scot %p our.bowl)/azimuth/(scot %da now.bowl)/last-snap/noun
|
||||
==
|
||||
::
|
||||
;< ~ bind:m
|
||||
%- flog-text %+ weld "naive-csv: processing {<net>} ethereum logs "
|
||||
"with {<(lent events)>} events"
|
||||
=/ =rolls-map
|
||||
(compute-effects nas.snap events net naive-contract chain-id)
|
||||
;< ~ bind:m (flog-text "naive-csv: getting timestamps")
|
||||
;< tim=thread-result bind:m
|
||||
%+ await-thread %eth-get-timestamps
|
||||
!>([node-url ~(tap in ~(key by rolls-map))])
|
||||
=/ timestamps %- ~(gas by *(map blocknum @da))
|
||||
?- tim
|
||||
[%.y *] ;;((list [@ud @da]) q.p.tim)
|
||||
[%.n *]
|
||||
=> (mean 'naive-csv: %eth-get-timestamps failed' p.tim)
|
||||
!!
|
||||
==
|
||||
;< ~ bind:m (flog-text "naive-csv: got timestamps")
|
||||
;< ~ bind:m (flog-text "naive-csv: getting tx receipts")
|
||||
;< gaz=thread-result bind:m
|
||||
%+ await-thread %eth-get-tx-receipts
|
||||
!>([node-url (get-roll-hashes rolls-map)])
|
||||
=/ gas-sender %- ~(gas by *(map keccak [gas=@ud sender=address]))
|
||||
?- gaz
|
||||
[%.y *] (parse-gas-sender ;;((list [@t json]) q.p.gaz))
|
||||
[%.n *]
|
||||
=> (mean 'naive-csv: %eth-tx-receipts failed' p.gaz)
|
||||
!!
|
||||
==
|
||||
;< ~ bind:m (flog-text "naive-csv: got tx receipts")
|
||||
=/ csv=(list cord)
|
||||
(make-csv (flatten (collate-roll-data rolls-map timestamps gas-sender)))
|
||||
;< ~ bind:m (export-csv csv pax)
|
||||
;< ~ bind:m (flog-text :(weld "naive-csv: csv saved to %" (spud pax) "/"))
|
||||
::
|
||||
(pure:m !>(~))
|
||||
:: +collate-roll-data throws naive:effects, timestamps, and gas costs into
|
||||
:: one $block-map
|
||||
::
|
||||
++ collate-roll-data
|
||||
|= $: =rolls-map
|
||||
timestamps=(map blocknum @da)
|
||||
roll-receipts=(map keccak [gas=@ud sender=address])
|
||||
==
|
||||
=/ blocknums=(list blocknum) ~(tap in ~(key by rolls-map))
|
||||
=| =block-map
|
||||
^+ block-map
|
||||
|-
|
||||
?~ blocknums block-map
|
||||
=/ =blocknum i.blocknums
|
||||
=/ rolls=(map keccak [[gas=@ud sender=address] =effects:naive])
|
||||
%- ~(gas by *(map keccak [[gas=@ud sender=address] =effects:naive]))
|
||||
%+ turn ~(tap in ~(key by (~(got by rolls-map) blocknum)))
|
||||
|= txh=keccak
|
||||
:+ txh
|
||||
(~(got by roll-receipts) txh)
|
||||
(~(got by (~(got by rolls-map) blocknum)) txh)
|
||||
%= $
|
||||
blocknums t.blocknums
|
||||
block-map %+ ~(put by block-map)
|
||||
blocknum
|
||||
[(~(got by timestamps) blocknum) rolls]
|
||||
==
|
||||
:: +flatten takes a $block-map and creates a $tx-data for every transaction
|
||||
:: in every roll, returned as a (list tx-data)
|
||||
::
|
||||
++ flatten
|
||||
|= =block-map
|
||||
=/ blocks=(list [blocknum block-dat]) ~(tap by block-map)
|
||||
=| tx-list=(list tx-data)
|
||||
^+ tx-list
|
||||
:: recurse through the list of blocks, getting the rolls submitted in that
|
||||
:: block, their timestamp, and the gas price of that roll
|
||||
::
|
||||
|-
|
||||
=* block-loop $
|
||||
?~ blocks tx-list
|
||||
=/ block=[=blocknum =block-dat] i.blocks
|
||||
=/ roll-list=(list [=keccak =roll-dat]) ~(tap by rolls.block-dat.block)
|
||||
=| block-tx-list=(list tx-data)
|
||||
:: recurse through each roll, getting the transaction data from the effects
|
||||
::
|
||||
|-
|
||||
=* roll-loop $
|
||||
?~ roll-list
|
||||
%= block-loop
|
||||
blocks t.blocks
|
||||
tx-list (welp tx-list block-tx-list)
|
||||
==
|
||||
=/ roll=[=keccak =roll-dat] i.roll-list
|
||||
:: recurse through the list of effects, building up transaction data as we
|
||||
:: go. there's a choice here to use the effects, or the submitted
|
||||
:: raw-tx. the effects include whether or not a transaction failed,
|
||||
:: which is important data not a part of the submitted raw-tx. we
|
||||
:: could determine this ourselves, but we build the effects anyways when
|
||||
:: computing the state transitions, so we may as well use them.
|
||||
::
|
||||
:: an individual transaction results in up to 3 diffs: a %nonce, a %tx, and
|
||||
:: a %point. they always appear in this order. successful transactions
|
||||
:: always have all 3, while failed transactions only have %nonce and %tx.
|
||||
:: note that the nonce listed is always the expected nonce - we can't know
|
||||
:: what nonce was actually submitted without the private key of the signer.
|
||||
::
|
||||
=| roll-tx-list=(list tx-data)
|
||||
=| =tx-data
|
||||
=| nonce-and-tx=[_| _|]
|
||||
|-
|
||||
=* effect-loop $
|
||||
:: if we are processing a new transaction, initialize the parts of tx-data
|
||||
:: that are identical for every transaction in the roll
|
||||
=? tx-data =([| |] nonce-and-tx)
|
||||
:* blocknum.block timestamp.block-dat.block sender.roll-dat.roll
|
||||
keccak.roll *keccak *ship *proxy:naive *nonce:naive
|
||||
gas.roll-dat.roll *@ | *action *ship
|
||||
==
|
||||
:: if we've gotten both the %nonce and %tx diff from a transaction, add the
|
||||
:: tx-data to the list of tx for the roll
|
||||
::
|
||||
?: =([& &] nonce-and-tx)
|
||||
%= effect-loop
|
||||
nonce-and-tx [| |]
|
||||
roll-tx-list (snoc roll-tx-list tx-data)
|
||||
==
|
||||
:: if we've finished looping through the effects, add the tx list from the
|
||||
:: roll to the list of tx for the block
|
||||
::
|
||||
?~ effects.roll-dat.roll
|
||||
%= roll-loop
|
||||
roll-list t.roll-list
|
||||
block-tx-list (welp block-tx-list roll-tx-list)
|
||||
==
|
||||
::
|
||||
=/ =diff:naive i.effects.roll-dat.roll
|
||||
:: we ignore %operator, %dns, %point diffs
|
||||
::
|
||||
?+ diff
|
||||
$(effects.roll-dat.roll t.effects.roll-dat.roll)
|
||||
:: %nonce is always the first diff from a given transaction.
|
||||
::
|
||||
[%nonce *]
|
||||
%= effect-loop
|
||||
-.nonce-and-tx &
|
||||
sender.tx-data ship.diff
|
||||
nonce.tx-data nonce.diff
|
||||
proxy.tx-data proxy.diff
|
||||
parent.tx-data (^sein:title ship.diff)
|
||||
effects.roll-dat.roll t.effects.roll-dat.roll
|
||||
==
|
||||
:: %tx is always the second diff from a given transaction.
|
||||
::
|
||||
[%tx *]
|
||||
%= effect-loop
|
||||
+.nonce-and-tx &
|
||||
effects.roll-dat.roll t.effects.roll-dat.roll
|
||||
action.tx-data +<.tx.raw-tx.diff
|
||||
suc.tx-data ?~ err.diff & |
|
||||
length.tx-data `@`-.raw.raw-tx.diff
|
||||
tx-hash.tx-data (hash-raw-tx:naive-tx raw-tx.diff)
|
||||
==
|
||||
==
|
||||
::
|
||||
++ parse-gas-sender
|
||||
|= res=(list [@t json])
|
||||
^- (list [=keccak [gas=@ud sender=address]])
|
||||
%+ turn res
|
||||
|= [id=@t =json]
|
||||
^- [=keccak [gas=@ud sender=address]]
|
||||
:- (hex-to-num:ethereum id)
|
||||
:- %- parse-hex-result:rpc:ethereum
|
||||
~| json
|
||||
?> ?=(%o -.json)
|
||||
(~(got by p.json) 'effectiveGasPrice') :: gas used in wei
|
||||
%- parse-hex-result:rpc:ethereum
|
||||
~| json
|
||||
?> ?=(%o -.json)
|
||||
(~(got by p.json) 'from')
|
||||
:: +get-roll-hashes makes a list of hashes of all transactions from $rolls-map
|
||||
::
|
||||
++ get-roll-hashes
|
||||
|= =rolls-map ^- (list keccak)
|
||||
%- zing
|
||||
%+ turn ~(val by rolls-map)
|
||||
|= a=(map keccak effects:naive)
|
||||
~(tap in ~(key by a))
|
||||
:: +compute-effects calls +naive to compute the state transitions for all
|
||||
:: logs, but it returns a map that only has the effects for L2 transactions,
|
||||
:: leaving out L1 transactions. we need to compute all of them in order to
|
||||
:: determine whether the transactions were valid.
|
||||
::
|
||||
++ compute-effects
|
||||
|= $: nas=^state:naive
|
||||
=events
|
||||
=net
|
||||
naive-contract=address
|
||||
chain-id=@ud
|
||||
==
|
||||
=| out=rolls-map
|
||||
^+ out
|
||||
::
|
||||
|-
|
||||
?~ events out
|
||||
=/ log=event-log:rpc:ethereum i.events
|
||||
?~ mined.log
|
||||
~& >> 'naive-csv: empty log'
|
||||
$(events t.events)
|
||||
=/ =blocknum block-number.u.mined.log
|
||||
=/ =^input:naive
|
||||
:- blocknum
|
||||
?. =(naive-contract address.log)
|
||||
:- %log
|
||||
[address.log (data-to-hex:dice data.log) topics.log]
|
||||
?~ input.u.mined.log
|
||||
~& >> 'naive-csv: empty L2 transaction'
|
||||
[%bat *@]
|
||||
[%bat u.input.u.mined.log]
|
||||
=^ =effects:naive nas
|
||||
(%*(. naive lac |) verifier:naive-tx chain-id nas input)
|
||||
%= $
|
||||
events t.events
|
||||
out ?. =(%bat +<.input)
|
||||
out :: skip L1 logs
|
||||
=/ cur (~(get by out) blocknum)
|
||||
?~ cur
|
||||
%+ ~(put by out) blocknum
|
||||
(my [[transaction-hash.u.mined.log effects]~])
|
||||
%+ ~(put by out) blocknum
|
||||
(~(put by u.cur) transaction-hash.u.mined.log effects)
|
||||
==
|
||||
:: +export-csv writes a (list cord) as csv to disk at .pax
|
||||
::
|
||||
++ export-csv
|
||||
|= [in=(list cord) pax=path]
|
||||
=/ m (strand ,~)
|
||||
^- form:m
|
||||
;< =bowl:spider bind:m get-bowl
|
||||
=- (send-raw-card %pass / %arvo %c %info -)
|
||||
%+ foal:space:userlib
|
||||
;: weld
|
||||
/(scot %p our.bowl)/base/(scot %da now.bowl)
|
||||
pax
|
||||
/(scot %da now.bowl)/txt
|
||||
==
|
||||
[%txt !>(in)]
|
||||
:: +make-csv takes in a (list tx-data) and makes it into a (list cord) to be
|
||||
:: saved as a csv file
|
||||
::
|
||||
++ make-csv
|
||||
|= in=(list tx-data)
|
||||
^- (list cord)
|
||||
:- %- crip
|
||||
;: weld
|
||||
"block number,"
|
||||
"timestamp,"
|
||||
"roller address,"
|
||||
"roll hash,"
|
||||
"tx hash,"
|
||||
"sending ship,"
|
||||
"sending proxy,"
|
||||
"nonce,"
|
||||
"gas price,"
|
||||
"length of input data,"
|
||||
"success or failure,"
|
||||
"function name,"
|
||||
"parent"
|
||||
==
|
||||
%+ turn in
|
||||
|= =tx-data
|
||||
%- crip
|
||||
;: weld
|
||||
(scow %ud blocknum.tx-data) ","
|
||||
(scow %da timestamp.tx-data) ","
|
||||
(scow %ux roller.tx-data) ","
|
||||
(scow %ux roll-hash.tx-data) ","
|
||||
(scow %ux tx-hash.tx-data) ","
|
||||
(scow %p sender.tx-data) ","
|
||||
(scow %tas proxy.tx-data) ","
|
||||
(scow %ud nonce.tx-data) ","
|
||||
(scow %ud gas.tx-data) ","
|
||||
(scow %ux length.tx-data) ","
|
||||
(scow %f suc.tx-data) ","
|
||||
(scow %tas action.tx-data) ","
|
||||
(scow %p parent.tx-data)
|
||||
==
|
||||
--
|
Loading…
Reference in New Issue
Block a user