From 1f95e6431e5f44a468c65c56fc705e5d82dcf997 Mon Sep 17 00:00:00 2001 From: lukechampine Date: Wed, 5 Feb 2025 11:47:44 -0500 Subject: [PATCH 1/2] mod: Update core dependency --- api/api_test.go | 12 +++--- cmd/walletd/node.go | 2 +- go.mod | 18 ++++++-- go.sum | 67 +++++++++++++++++++++++++----- wallet/update.go | 96 ++++++++++++++++++------------------------- wallet/wallet.go | 62 +++++++++++++++------------- wallet/wallet_test.go | 30 +++++--------- 7 files changed, 161 insertions(+), 126 deletions(-) diff --git a/api/api_test.go b/api/api_test.go index 21342e2..1c29341 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -956,7 +956,7 @@ func TestP2P(t *testing.T) { UniqueID: gateway.GenerateUniqueID(), NetAddress: l1.Addr().String(), }) - go s1.Run(context.Background()) + go s1.Run() defer s1.Close() c1 := runServer(t, cm1, s1, wm1) w1, err := c1.AddWallet(api.WalletUpdateRequest{Name: "primary"}) @@ -999,7 +999,7 @@ func TestP2P(t *testing.T) { UniqueID: gateway.GenerateUniqueID(), NetAddress: l2.Addr().String(), }, syncer.WithLogger(zaptest.NewLogger(t))) - go s2.Run(context.Background()) + go s2.Run() defer s2.Close() c2 := runServer(t, cm2, s2, wm2) @@ -1964,7 +1964,7 @@ func TestDebugMine(t *testing.T) { NetAddress: l.Addr().String(), }) defer s.Close() - go s.Run(context.Background()) + go s.Run() wm, err := wallet.NewManager(cm, ws, wallet.WithLogger(log.Named("wallet"))) if err != nil { @@ -2025,7 +2025,7 @@ func TestAPISecurity(t *testing.T) { NetAddress: syncerListener.Addr().String(), }) defer s.Close() - go s.Run(context.Background()) + go s.Run() wm, err := wallet.NewManager(cm, ws, wallet.WithLogger(log.Named("wallet"))) if err != nil { @@ -2140,7 +2140,7 @@ func TestAPINoContent(t *testing.T) { NetAddress: l.Addr().String(), }) defer s.Close() - go s.Run(context.Background()) + go s.Run() wm, err := wallet.NewManager(cm, ws, wallet.WithLogger(log.Named("wallet"))) if err != nil { @@ -2207,7 +2207,7 @@ func TestV2TransactionUpdateBasis(t *testing.T) { NetAddress: l.Addr().String(), }) defer s.Close() - go s.Run(context.Background()) + go s.Run() wm, err := wallet.NewManager(cm, ws, wallet.WithLogger(log.Named("wallet")), wallet.WithIndexMode(wallet.IndexModeFull)) if err != nil { diff --git a/cmd/walletd/node.go b/cmd/walletd/node.go index e9a5b57..c0ec30c 100644 --- a/cmd/walletd/node.go +++ b/cmd/walletd/node.go @@ -193,7 +193,7 @@ func runNode(ctx context.Context, cfg config.Config, log *zap.Logger, enableDebu s := syncer.New(syncerListener, cm, ps, header, syncer.WithLogger(log.Named("syncer"))) defer s.Close() - go s.Run(ctx) + go s.Run() wm, err := wallet.NewManager(cm, store, wallet.WithLogger(log.Named("wallet")), wallet.WithIndexMode(cfg.Index.Mode), wallet.WithSyncBatchSize(cfg.Index.BatchSize)) if err != nil { diff --git a/go.mod b/go.mod index def24bb..c8a5ab9 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ toolchain go1.23.2 require ( github.com/mattn/go-sqlite3 v1.14.24 - go.sia.tech/core v0.9.1 - go.sia.tech/coreutils v0.10.1 + go.sia.tech/core v0.10.0 + go.sia.tech/coreutils v0.11.0 go.sia.tech/jape v0.12.1 go.sia.tech/web/walletd v0.27.0 go.uber.org/zap v1.27.0 @@ -19,12 +19,24 @@ require ( ) require ( + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect + github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect + github.com/onsi/ginkgo/v2 v2.12.0 // indirect + github.com/quic-go/qpack v0.5.1 // indirect + github.com/quic-go/quic-go v0.49.0 // indirect + github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 // indirect go.etcd.io/bbolt v1.3.11 // indirect go.sia.tech/mux v1.3.0 // indirect - go.sia.tech/web v0.0.0-20240610131903-5611d44a533e // indirect + go.sia.tech/web v0.0.0-20240422221546-c1709d16b6ef // indirect + go.uber.org/mock v0.5.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.32.0 // indirect + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect + golang.org/x/mod v0.18.0 // indirect + golang.org/x/net v0.34.0 // indirect + golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.29.0 // indirect + golang.org/x/text v0.21.0 // indirect golang.org/x/tools v0.22.0 // indirect ) diff --git a/go.sum b/go.sum index 3516842..ad9e4da 100644 --- a/go.sum +++ b/go.sum @@ -1,47 +1,92 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk= +github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f h1:pDhu5sgp8yJlEF/g6osliIIpF9K4F5jvkULXa4daRDQ= +github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/onsi/ginkgo/v2 v2.12.0 h1:UIVDowFPwpg6yMUpPjGkYvf06K3RAiJXUhCxEwQVHRI= +github.com/onsi/ginkgo/v2 v2.12.0/go.mod h1:ZNEzXISYlqpb8S36iN71ifqLi3vVD1rVJGvWRCJOUpQ= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= +github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= +github.com/quic-go/quic-go v0.49.0 h1:w5iJHXwHxs1QxyBv1EHKuC50GX5to8mJAxvtnttJp94= +github.com/quic-go/quic-go v0.49.0/go.mod h1:s2wDnmCdooUQBmQfpUSTCYBl1/D4FcqbULMMkASvR6s= +github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 h1:4WFk6u3sOT6pLa1kQ50ZVdm8BQFgJNA117cepZxtLIg= +github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66/go.mod h1:Vp72IJajgeOL6ddqrAhmp7IM9zbTcgkQxD/YdxrVwMw= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0= go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I= -go.sia.tech/core v0.9.1 h1:p65iVQP4OnLRvPHBbZDhUR0LFserNIY82M/4de/gNPo= -go.sia.tech/core v0.9.1/go.mod h1:7buI+3k5xO+9PdzBQJlogOAc5h+twDUxEpV6EuXWZ5A= -go.sia.tech/coreutils v0.10.1 h1:qs6JIUhzQGcWYdMoE0KURz8g+Wt+OI65KMmyc4or/DA= -go.sia.tech/coreutils v0.10.1/go.mod h1:99k+BlLKYsKHNdZAr5KqYIhoamPEbwhKZdq4FDV4HtU= +go.sia.tech/core v0.10.0 h1:EK/JtUqbATeZm+K+a7fKtCCtPYinu9p45pOFSTUHx6o= +go.sia.tech/core v0.10.0/go.mod h1:49Ti4JnaLjQXXjEjRnO5HyLKDue1GHuFyz3XECM2Mlw= +go.sia.tech/coreutils v0.11.0 h1:6qSStFdKFjnzDg34o+ohy5BXD1IGjEowXn/WV+r7eW8= +go.sia.tech/coreutils v0.11.0/go.mod h1:7sh8UsgV/YSd8njHQeZgWd+u5Twr+4iuHmDuOVwj9hI= go.sia.tech/jape v0.12.1 h1:xr+o9V8FO8ScRqbSaqYf9bjj1UJ2eipZuNcI1nYousU= go.sia.tech/jape v0.12.1/go.mod h1:wU+h6Wh5olDjkPXjF0tbZ1GDgoZ6VTi4naFw91yyWC4= go.sia.tech/mux v1.3.0 h1:hgR34IEkqvfBKUJkAzGi31OADeW2y7D6Bmy/Jcbop9c= go.sia.tech/mux v1.3.0/go.mod h1:I46++RD4beqA3cW9Xm9SwXbezwPqLvHhVs9HLpDtt58= -go.sia.tech/web v0.0.0-20240610131903-5611d44a533e h1:oKDz6rUExM4a4o6n/EXDppsEka2y/+/PgFOZmHWQRSI= -go.sia.tech/web v0.0.0-20240610131903-5611d44a533e/go.mod h1:4nyDlycPKxTlCqvOeRO0wUfXxyzWCEE7+2BRrdNqvWk= +go.sia.tech/web v0.0.0-20240422221546-c1709d16b6ef h1:X0Xm9AQYHhdd85yi9gqkkCZMb9/WtLwC0nDgv65N90Y= +go.sia.tech/web v0.0.0-20240422221546-c1709d16b6ef/go.mod h1:nGEhGmI8zV/BcC3LOCC5JLVYpidNYJIvLGIqVRWQBCg= go.sia.tech/web/walletd v0.27.0 h1:oTCqqZHvvWbcy/jKMN7urBEFYXQs1+yVzuKu17vgQtk= go.sia.tech/web/walletd v0.27.0/go.mod h1:VkWPLolV88EeAlGzTxSktwQRQ5+MZdkWan0N4d5aCZ8= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= lukechampine.com/flagg v1.1.1 h1:jB5oL4D5zSUrzm5og6dDEi5pnrTF1poKfC7KE1lLsqc= diff --git a/wallet/update.go b/wallet/update.go index af410c7..7001b8a 100644 --- a/wallet/update.go +++ b/wallet/update.go @@ -93,43 +93,36 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate, indexMode IndexMode) e } // add new siacoin elements to the store - cau.ForEachSiacoinElement(func(se types.SiacoinElement, created, spent bool) { - if (created && spent) || se.SiacoinOutput.Value.IsZero() { - return - } - - relevant, err := tx.AddressRelevant(se.SiacoinOutput.Address) - if err != nil { + for _, sced := range cau.SiacoinElementDiffs() { + sce := sced.SiacoinElement + if (sced.Created && sced.Spent) || sce.SiacoinOutput.Value.IsZero() { + continue + } else if relevant, err := tx.AddressRelevant(sce.SiacoinOutput.Address); err != nil { panic(err) } else if !relevant { - return + continue } - - if spent { - applied.SpentSiacoinElements = append(applied.SpentSiacoinElements, se) + if sced.Spent { + applied.SpentSiacoinElements = append(applied.SpentSiacoinElements, sce) } else { - applied.CreatedSiacoinElements = append(applied.CreatedSiacoinElements, se) - } - }) - - cau.ForEachSiafundElement(func(se types.SiafundElement, created, spent bool) { - if (created && spent) || se.SiafundOutput.Value == 0 { - return + applied.CreatedSiacoinElements = append(applied.CreatedSiacoinElements, sce) } - - relevant, err := tx.AddressRelevant(se.SiafundOutput.Address) - if err != nil { + } + for _, sfed := range cau.SiafundElementDiffs() { + sfe := sfed.SiafundElement + if (sfed.Created && sfed.Spent) || sfe.SiafundOutput.Value == 0 { + continue + } else if relevant, err := tx.AddressRelevant(sfe.SiafundOutput.Address); err != nil { panic(err) } else if !relevant { - return + continue } - - if spent { - applied.SpentSiafundElements = append(applied.SpentSiafundElements, se) + if sfed.Spent { + applied.SpentSiafundElements = append(applied.SpentSiafundElements, sfe) } else { - applied.CreatedSiafundElements = append(applied.CreatedSiafundElements, se) + applied.CreatedSiafundElements = append(applied.CreatedSiafundElements, sfe) } - }) + } // add events relevant := func(addr types.Address) bool { @@ -176,47 +169,38 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types. } } - cru.ForEachSiacoinElement(func(se types.SiacoinElement, created, spent bool) { - if created && spent { - return - } - - relevant, err := tx.AddressRelevant(se.SiacoinOutput.Address) - if err != nil { + for _, sced := range cru.SiacoinElementDiffs() { + sce := sced.SiacoinElement + if (sced.Created && sced.Spent) || sce.SiacoinOutput.Value.IsZero() { + continue + } else if relevant, err := tx.AddressRelevant(sce.SiacoinOutput.Address); err != nil { panic(err) } else if !relevant { - return + continue } - - if spent { + if sced.Spent { // re-add any spent siacoin elements - reverted.UnspentSiacoinElements = append(reverted.UnspentSiacoinElements, se) + reverted.UnspentSiacoinElements = append(reverted.UnspentSiacoinElements, sce) } else { // delete any created siacoin elements - reverted.DeletedSiacoinElements = append(reverted.DeletedSiacoinElements, se) - } - }) - - cru.ForEachSiafundElement(func(se types.SiafundElement, created, spent bool) { - if created && spent { - return + reverted.DeletedSiacoinElements = append(reverted.DeletedSiacoinElements, sce) } - - relevant, err := tx.AddressRelevant(se.SiafundOutput.Address) - if err != nil { + } + for _, sfed := range cru.SiafundElementDiffs() { + sfe := sfed.SiafundElement + if (sfed.Created && sfed.Spent) || sfe.SiafundOutput.Value == 0 { + continue + } else if relevant, err := tx.AddressRelevant(sfe.SiafundOutput.Address); err != nil { panic(err) } else if !relevant { - return + continue } - - if spent { - // re-add any spent siafund elements - reverted.UnspentSiafundElements = append(reverted.UnspentSiafundElements, se) + if sfed.Spent { + reverted.UnspentSiafundElements = append(reverted.UnspentSiafundElements, sfe) } else { - // delete any created siafund elements - reverted.DeletedSiafundElements = append(reverted.DeletedSiafundElements, se) + reverted.DeletedSiafundElements = append(reverted.DeletedSiafundElements, sfe) } - }) + } if err := tx.RevertIndex(revertedIndex, reverted); err != nil { return fmt.Errorf("failed to revert index: %w", err) diff --git a/wallet/wallet.go b/wallet/wallet.go index e28e5a0..1430582 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -79,10 +79,10 @@ type ( // A ChainUpdate is a set of changes to the consensus state. ChainUpdate interface { - ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool)) - ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool)) - ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool)) - ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType)) + SiacoinElementDiffs() []consensus.SiacoinElementDiff + SiafundElementDiffs() []consensus.SiafundElementDiff + FileContractElementDiffs() []consensus.FileContractElementDiff + V2FileContractElementDiffs() []consensus.V2FileContractElementDiff } ) @@ -153,18 +153,18 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f }) } - anythingRelevant := func() (ok bool) { - cu.ForEachSiacoinElement(func(sce types.SiacoinElement, _, _ bool) { - if ok || relevant(sce.SiacoinOutput.Address) { - ok = true + anythingRelevant := func() bool { + for _, sced := range cu.SiacoinElementDiffs() { + if relevant(sced.SiacoinElement.SiacoinOutput.Address) { + return true } - }) - cu.ForEachSiafundElement(func(sfe types.SiafundElement, _, _ bool) { - if ok || relevant(sfe.SiafundOutput.Address) { - ok = true + } + for _, sfed := range cu.SiafundElementDiffs() { + if relevant(sfed.SiafundElement.SiafundOutput.Address) { + return true } - }) - return + } + return false }() if !anythingRelevant { return nil @@ -173,14 +173,16 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f // collect all elements sces := make(map[types.SiacoinOutputID]types.SiacoinElement) sfes := make(map[types.SiafundOutputID]types.SiafundElement) - cu.ForEachSiacoinElement(func(sce types.SiacoinElement, _, _ bool) { + for _, sced := range cu.SiacoinElementDiffs() { + sce := sced.SiacoinElement sce.StateElement.MerkleProof = nil - sces[types.SiacoinOutputID(sce.ID)] = sce - }) - cu.ForEachSiafundElement(func(sfe types.SiafundElement, _, _ bool) { + sces[sce.ID] = sce + } + for _, sfed := range cu.SiafundElementDiffs() { + sfe := sfed.SiafundElement sfe.StateElement.MerkleProof = nil - sfes[types.SiafundOutputID(sfe.ID)] = sfe - }) + sfes[sfe.ID] = sfe + } // handle v1 transactions for _, txn := range b.Transactions { @@ -294,14 +296,15 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f } // handle contracts - cu.ForEachFileContractElement(func(fce types.FileContractElement, _ bool, rev *types.FileContractElement, resolved, valid bool) { - if !resolved { - return + for _, fced := range cu.FileContractElementDiffs() { + if !fced.Resolved { + continue } + fce := fced.FileContractElement fce.StateElement.MerkleProof = nil - if valid { + if fced.Valid { for i := range fce.FileContract.ValidProofOutputs { address := fce.FileContract.ValidProofOutputs[i].Address if !relevant(address) { @@ -330,13 +333,14 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f }, []types.Address{address}) } } - }) + } - cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, _ bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { + for _, fced := range cu.V2FileContractElementDiffs() { + fce := fced.V2FileContractElement + res := fced.Resolution if res == nil { - return + continue } - fce.StateElement.MerkleProof = nil var missed bool @@ -367,7 +371,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f Missed: missed, }, []types.Address{fce.V2FileContract.RenterOutput.Address}) } - }) + } // handle block rewards for i := range b.MinerPayouts { diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index a5ad9e4..d9d3c18 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -3566,11 +3566,8 @@ func TestEventTypes(t *testing.T) { } // get the confirmed file contract element - var fce types.V2FileContractElement - applied[0].ForEachV2FileContractElement(func(ele types.V2FileContractElement, _ bool, _ *types.V2FileContractElement, _ types.V2FileContractResolutionType) { - fce = ele - }) - for _, cau := range applied { + fce := applied[0].V2FileContractElementDiffs()[0].V2FileContractElement + for _, cau := range applied[1:] { cau.UpdateElementProof(&fce.StateElement) } @@ -3657,12 +3654,8 @@ func TestEventTypes(t *testing.T) { } // get the confirmed file contract element - var fce types.V2FileContractElement - applied[0].ForEachV2FileContractElement(func(ele types.V2FileContractElement, _ bool, _ *types.V2FileContractElement, _ types.V2FileContractResolutionType) { - fce = ele - }) - // update its proof - for _, cau := range applied { + fce := applied[0].V2FileContractElementDiffs()[0].V2FileContractElement + for _, cau := range applied[1:] { cau.UpdateElementProof(&fce.StateElement) } // get the proof index element @@ -3754,11 +3747,8 @@ func TestEventTypes(t *testing.T) { } // get the confirmed file contract element - var fce types.V2FileContractElement - applied[0].ForEachV2FileContractElement(func(ele types.V2FileContractElement, _ bool, _ *types.V2FileContractElement, _ types.V2FileContractResolutionType) { - fce = ele - }) - for _, cau := range applied { + fce := applied[0].V2FileContractElementDiffs()[0].V2FileContractElement + for _, cau := range applied[1:] { cau.UpdateElementProof(&fce.StateElement) } @@ -4445,11 +4435,11 @@ func TestReset(t *testing.T) { var siacoinElements []types.SiacoinElement for _, cau := range applied { - cau.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) { - if created && sce.SiacoinOutput.Address == addr { - siacoinElements = append(siacoinElements, sce) + for _, sced := range cau.SiacoinElementDiffs() { + if sced.Created && sced.SiacoinElement.SiacoinOutput.Address == addr { + siacoinElements = append(siacoinElements, sced.SiacoinElement) } - }) + } } var expectedSiacoins, expectedImmature types.Currency From f9c1d01ee87bf16f35c67bbc7cad15ee26c69736 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 7 Feb 2025 10:39:46 -0800 Subject: [PATCH 2/2] document change --- ..._response_of_consensus_updates_endpoint.md | 243 ++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 .changeset/simplified_response_of_consensus_updates_endpoint.md diff --git a/.changeset/simplified_response_of_consensus_updates_endpoint.md b/.changeset/simplified_response_of_consensus_updates_endpoint.md new file mode 100644 index 0000000..5eab007 --- /dev/null +++ b/.changeset/simplified_response_of_consensus_updates_endpoint.md @@ -0,0 +1,243 @@ +--- +default: major +--- + +# Simplified response of consensus updates endpoint + +The response of `/api/consensus/updates/:index` has been simplified to make it easier for developers to index chain state. + +```json +{ + "applied": [ + { + "update": { + "siacoinElements": [ + { + "siacoinElement": { + "id": "35b81e41f594d7faeb88bd8eaac2eaa68ce99fe1c8fe5f0cba8fafa65ab3a70e", + "stateElement": { + "leafIndex": 0, + "merkleProof": [ + "88052fa2d1e22e4a5542fed9686cdad3fbeccbc60d15d4fd36a7691d61add1e1" + ] + }, + "siacoinOutput": { + "value": "1000000000000000000000000000000000000", + "address": "3d7f707d05f2e0ec7ccc9220ed7c8af3bc560fbee84d068c2cc28151d617899e1ee8bc069946" + }, + "maturityHeight": 0 + }, + "created": true, + "spent": false + } + ], + "siafundElementDiffs": [ + { + "siafundElement": { + "id": "69ad26a0fbd1a6985d2053246650bb3ba5f3491d818748b6c8562db1ddb2c45b", + "stateElement": { + "leafIndex": 1, + "merkleProof": [ + "837482a39d5bf66f07bae3b89191e4375b82c9f341ce6a17e22e14e0333ab9f6" + ] + }, + "siafundOutput": { + "value": 10000, + "address": "053b2def3cbdd078c19d62ce2b4f0b1a3c5e0ffbeeff01280efb1f8969b2f5bb4fdc680f0807" + }, + "claimStart": "0" + }, + "created": true, + "spent": false + } + ], + "fileContractElementDiffs": null, + "v2FileContractElementDiffs": null, + "attestationElements": null, + "chainIndexElement": { + "id": "e23d2ee56fc5c79618ead2f8f36c1b72c6f3ec5e0f751c05e08bd6665a6ec22a", + "stateElement": { + "leafIndex": 2 + }, + "chainIndex": { + "height": 0, + "id": "e23d2ee56fc5c79618ead2f8f36c1b72c6f3ec5e0f751c05e08bd6665a6ec22a" + } + }, + "updatedLeaves": {}, + "treeGrowth": {}, + "oldNumLeaves": 0, + "numLeaves": 3 + }, + "state": { + "index": { + "height": 0, + "id": "e23d2ee56fc5c79618ead2f8f36c1b72c6f3ec5e0f751c05e08bd6665a6ec22a" + }, + "prevTimestamps": [ + "2023-01-13T00:53:20-08:00", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z" + ], + "depth": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "childTarget": "0000000100000000000000000000000000000000000000000000000000000000", + "siafundTaxRevenue": "0", + "oakTime": 0, + "oakTarget": "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff", + "foundationSubsidyAddress": "053b2def3cbdd078c19d62ce2b4f0b1a3c5e0ffbeeff01280efb1f8969b2f5bb4fdc680f0807", + "foundationManagementAddress": "000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69", + "totalWork": "1", + "difficulty": "4294967295", + "oakWork": "4294967297", + "elements": { + "numLeaves": 3, + "trees": [ + "e1c3af98d77463b767d973f8a563947d949d06428ff145db30143a2811d10014", + "134b1f08aec0c7fbc50203a514277d197947e3da3ab1854749bf093b56402912" + ] + }, + "attestations": 0 + }, + "block": { + "parentID": "0000000000000000000000000000000000000000000000000000000000000000", + "nonce": 0, + "timestamp": "2023-01-13T00:53:20-08:00", + "minerPayouts": [], + "transactions": [ + { + "id": "268ef8627241b3eb505cea69b21379c4b91c21dfc4b3f3f58c66316249058cfd", + "siacoinOutputs": [ + { + "value": "1000000000000000000000000000000000000", + "address": "3d7f707d05f2e0ec7ccc9220ed7c8af3bc560fbee84d068c2cc28151d617899e1ee8bc069946" + } + ], + "siafundOutputs": [ + { + "value": 10000, + "address": "053b2def3cbdd078c19d62ce2b4f0b1a3c5e0ffbeeff01280efb1f8969b2f5bb4fdc680f0807" + } + ] + } + ] + } + }, + { + "update": { + "siacoinElements": [ + { + "siacoinElement": { + "id": "ca02d6807c92f61af94e626604615fbcdb471f38fcd8f3add6c6e6e0485ce090", + "stateElement": { + "leafIndex": 3, + "merkleProof": [ + "e1c3af98d77463b767d973f8a563947d949d06428ff145db30143a2811d10014", + "134b1f08aec0c7fbc50203a514277d197947e3da3ab1854749bf093b56402912" + ] + }, + "siacoinOutput": { + "value": "300000000000000000000000000000", + "address": "c5e1ca930f193cfe4c72eaed8d3bbae627f67d6c8e32c406fe692b1c00b554f4731fddf2c752" + }, + "maturityHeight": 145 + }, + "created": true, + "spent": false + } + ], + "siafundElementDiffs": null, + "fileContractElementDiffs": null, + "v2FileContractElementDiffs": null, + "attestationElements": null, + "chainIndexElement": { + "id": "0000000028e731f0bb5d48662283bec83cca9427581b948d1036deb2b42c3006", + "stateElement": { + "leafIndex": 4 + }, + "chainIndex": { + "height": 1, + "id": "0000000028e731f0bb5d48662283bec83cca9427581b948d1036deb2b42c3006" + } + }, + "updatedLeaves": {}, + "treeGrowth": { + "0": [ + "190d98a7d8ff464e57f89dc916b155455ecf927f4c74b9edf5e80c103f052bfa", + "134b1f08aec0c7fbc50203a514277d197947e3da3ab1854749bf093b56402912" + ], + "1": [ + "2b082bec52801c1e61e5b0d0c1f5fc3925bd24e16d2f490afeb70374828586f1" + ] + }, + "oldNumLeaves": 3, + "numLeaves": 5 + }, + "state": { + "index": { + "height": 1, + "id": "0000000028e731f0bb5d48662283bec83cca9427581b948d1036deb2b42c3006" + }, + "prevTimestamps": [ + "2023-01-13T08:18:19-08:00", + "2023-01-13T00:53:20-08:00", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z", + "0001-01-01T00:00:00Z" + ], + "depth": "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff", + "childTarget": "0000000100000000000000000000000000000000000000000000000000000000", + "siafundTaxRevenue": "0", + "oakTime": 26699000000000, + "oakTarget": "000000008052201448053c59f99803e7a8165929036cd574d91425423191387c", + "foundationSubsidyAddress": "053b2def3cbdd078c19d62ce2b4f0b1a3c5e0ffbeeff01280efb1f8969b2f5bb4fdc680f0807", + "foundationManagementAddress": "000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69", + "totalWork": "4294967297", + "difficulty": "4294967295", + "oakWork": "8568459756", + "elements": { + "numLeaves": 5, + "trees": [ + "589fb425faa23be357492394813dc575505899d42d0b23a7162e1c68f7eeb227", + "750cc671d80aef6ee5c73344ba4e74eccda77d9f0cf51ed6237952b1d84bc336" + ] + }, + "attestations": 0 + }, + "block": { + "parentID": "e23d2ee56fc5c79618ead2f8f36c1b72c6f3ec5e0f751c05e08bd6665a6ec22a", + "nonce": 10689346, + "timestamp": "2023-01-13T08:18:19-08:00", + "minerPayouts": [ + { + "value": "300000000000000000000000000000", + "address": "c5e1ca930f193cfe4c72eaed8d3bbae627f67d6c8e32c406fe692b1c00b554f4731fddf2c752" + } + ], + "transactions": [ + { + "id": "1148417ad8fa6546646da6922618358210bc7a668ef7cb25f6a8a3605851bc7b", + "arbitraryData": [ + "Tm9uU2lhAAAAAAAAAAAAAClvJjNhfcbxtEfP2yfbBM4=" + ] + } + ] + } + } + ], + "reverted": null +} +``` \ No newline at end of file