Skip to content

Commit

Permalink
[#9927] Fast blocks sync afetr being offline
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jan 30, 2020
1 parent 6ff878c commit a5d9fdd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
15 changes: 8 additions & 7 deletions src/status_im/ethereum/subscriptions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
{:db (assoc-in db [:ethereum/subscriptions id] handler)})

(fx/defn new-block
[{:keys [db] :as cofx} historical? block-number accounts]
[{:keys [db] :as cofx} historical? block-number accounts transactions-per-account]
(let [{:keys [:wallet/all-tokens]} db
chain (ethereum/chain-keyword db)
chain-tokens (into {} (map (juxt :address identity)
(tokens/tokens-for all-tokens chain)))]
(log/debug "[wallet-subs] new-block"
"accounts" accounts
"block" block-number)
"block" block-number
"transactions-per-account" transactions-per-account)
(fx/merge cofx
(cond-> {}
(not historical?)
Expand All @@ -41,10 +42,10 @@
;;NOTE only get transfers if the new block contains some
;; from/to one of the multiaccount accounts
(not-empty accounts)
(assoc :transactions/get-transfers-from-block
(assoc :transactions/get-transfers
{:chain-tokens chain-tokens
:addresses accounts
:block block-number
:before-block block-number
:historical? historical?}))
(transactions/check-watched-transactions))))

Expand Down Expand Up @@ -91,12 +92,12 @@
:historical? true}}))

(fx/defn new-wallet-event
[cofx {:keys [type blockNumber accounts] :as event}]
[cofx {:keys [type blockNumber accounts newTransactions] :as event}]
(log/debug "[wallet-subs] new-wallet-event"
"event-type" type)
(case type
"newblock" (new-block cofx false blockNumber accounts)
"history" (new-block cofx true blockNumber accounts)
"newblock" (new-block cofx false blockNumber accounts newTransactions)
"history" (new-block cofx true blockNumber accounts nil)
"reorg" (reorg cofx event)
"recent-history-fetching" (recent-history-fetching-started cofx accounts)
"recent-history-ready" (recent-history-fetching-ended cofx event)
Expand Down
28 changes: 15 additions & 13 deletions src/status_im/ethereum/transactions/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,30 @@

(re-frame/reg-fx
:transactions/get-transfers
(fn [{:keys [chain-tokens addresses before-block page-size]
(fn [{:keys [chain-tokens addresses before-block page-size
transactions-per-address]
:as params
:or {page-size 0}}]
:or {page-size 20}}]
{:pre [(cljs.spec.alpha/valid?
(cljs.spec.alpha/coll-of string?)
addresses)]}
(log/debug "[transactions] get-transfers"
"addresses" addresses
"block" before-block
"page-size" page-size)
"page-size" page-size
"transactions-per-address" transactions-per-address)
(when before-block
(doseq [address addresses]
(json-rpc/call
{:method "wallet_getTransfersByAddress"
:params [address (encode/uint before-block) (encode/uint page-size)]
:on-success #(re-frame/dispatch
[::new-transfers
(enrich-transfers chain-tokens %)
(assoc params :address address)])
:on-error #(re-frame/dispatch [::tx-fetching-failed address])})))))
(let [page-size (or (get transactions-per-address address)
page-size)]
(json-rpc/call
{:method "wallet_getTransfersByAddress"
:params [address (encode/uint before-block) (encode/uint page-size)]
:on-success #(re-frame/dispatch
[::new-transfers
(enrich-transfers chain-tokens %)
(assoc params :address address)])
:on-error #(re-frame/dispatch [::tx-fetching-failed address])}))))))

(fx/defn initialize
[{:keys [db]} addresses]
Expand All @@ -261,7 +265,6 @@
{:transactions/get-transfers
{:chain-tokens chain-tokens
:addresses (map eip55/address->checksum addresses)
:page-size 20
:historical? true}}))

(fx/defn fetch-more-tx
Expand All @@ -282,6 +285,5 @@
{:chain-tokens chain-tokens
:addresses [address]
:before-block min-known-block
:page-size 20
:historical? true}}
(tx-fetching-in-progress [address]))))
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.41.0",
"commit-sha1": "8931b14c4e40261e6161a3c776bf16cc0fdd1f3a",
"src-sha256": "16r3xbzhh3fljpx11yahm1r5xh4cyvggy5avg6smkpw9m93cb6f7"
"version": "fast-block-sync-after-delay",
"commit-sha1": "c31188d3784242f4ae8515285c82ccc08061f9fd",
"src-sha256": "1s2akpjkkilbyfj3hn5rvsfb2m7qqnpxhx6v4min3qss4avjsaai"
}

0 comments on commit a5d9fdd

Please sign in to comment.