Skip to content

Commit 9f6ec58

Browse files
State syncer mempool syncing and test suite updates (#91)
* Update on conflict handling for block height collisions * Fix migration * block conflict enhancements * better uncommitted block handling * trigger build * fix utxo operation bundle parsing * Add testing suite to repo * Updates to config * Updates to testing params * More tests * Add tests * Updates to testing suite * Updates to tests * Updates to testing * Updates to handler * Updates to testing suite * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Empty commit to trigger build * Cleanup PR * Add new utils * Add functionality needed to handle websocket events on a pg-commit basis * Disable query log filtering --------- Co-authored-by: Lazy Nina <lazynina84@gmail.com> Co-authored-by: Lazy Nina <81658138+lazynina@users.noreply.github.com>
1 parent 763dec5 commit 9f6ec58

File tree

15 files changed

+2264
-53
lines changed

15 files changed

+2264
-53
lines changed

.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
STATE_CHANGE_DIR=/tmp/state-changes-test
22
CONSUMER_PROGRESS_DIR=/tmp/consumer-progress-test
33
DB_HOST=localhost
4-
DB_PORT=5432
4+
DB_PORT=5430
55
DB_USERNAME=postgres
66
DB_PASSWORD=postgres
77
DB_NAME=postgres
88
READONLY_USER_PASSWORD=postgres
9-
LOG_QUERIES=true
9+
LOG_QUERIES=false
1010
THREAD_LIMIT=10
1111
BATCH_BYTES=500000
1212
CALCULATE_EXPLORER_STATISTICS=true
13+
TEST_STARTER_DESO_SEED=verb find card ship another until version devote guilt strong lemon six
14+
NODE_URL=http://localhost:17001

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ dev:
44
dev-env:
55
docker compose -f local.docker-compose.yml build && docker compose -f local.docker-compose.yml up
66

7+
test-env:
8+
docker compose -f test.docker-compose.yml down --volumes && docker compose -f test.docker-compose.yml build && docker compose -f test.docker-compose.yml up
9+
710
dev-env-down:
811
docker compose -f local.docker-compose.yml down --volumes

entries/transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TransactionBatchOperation(entries []*lib.StateChangeEntry, db bun.IDB, para
134134
return nil
135135
}
136136

137-
func transformTransactionEntry(entries []*lib.StateChangeEntry, params *lib.DeSoParams) ([]*PGTransactionEntry, error) {
137+
func TransformTransactionEntry(entries []*lib.StateChangeEntry, params *lib.DeSoParams) ([]*PGTransactionEntry, error) {
138138
// Track the unique entries we've inserted so we don't insert the same entry twice.
139139
uniqueTransactions := consumer.UniqueEntries(entries)
140140
// Create a new array to hold the bun struct.
@@ -192,7 +192,7 @@ func bulkInsertTransactionEntry(entries []*PGTransactionEntry, db bun.IDB, opera
192192

193193
// transformAndBulkInsertTransactionEntry inserts a batch of user_association entries into the database.
194194
func transformAndBulkInsertTransactionEntry(entries []*lib.StateChangeEntry, db bun.IDB, operationType lib.StateSyncerOperationType, params *lib.DeSoParams) error {
195-
pgTransactionEntrySlice, err := transformTransactionEntry(entries, params)
195+
pgTransactionEntrySlice, err := TransformTransactionEntry(entries, params)
196196
if err != nil {
197197
return errors.Wrapf(err, "entries.transformAndBulkInsertTransactionEntry: Problem transforming transaction entries")
198198
}

go.mod

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ replace github.com/deso-protocol/backend => ../backend/
1111
replace github.com/deso-protocol/state-consumer => ../state-consumer/
1212

1313
require (
14+
github.com/btcsuite/btcd/btcec/v2 v2.3.4
15+
github.com/btcsuite/btcd/btcutil v1.1.6
1416
github.com/deso-protocol/backend v1.2.9
1517
github.com/deso-protocol/core v1.2.9
1618
github.com/deso-protocol/state-consumer v1.0.3
19+
github.com/deso-protocol/uint256 v1.3.2
1720
github.com/golang/glog v1.2.2
1821
github.com/google/uuid v1.6.0
22+
github.com/hashicorp/golang-lru/v2 v2.0.7
1923
github.com/pkg/errors v0.9.1
2024
github.com/spf13/viper v1.18.2
25+
github.com/stretchr/testify v1.10.0
26+
github.com/tyler-smith/go-bip39 v1.1.0
2127
github.com/uptrace/bun v1.2.3
2228
github.com/uptrace/bun/dialect/pgdialect v1.2.3
2329
github.com/uptrace/bun/driver/pgdriver v1.2.3
@@ -55,8 +61,6 @@ require (
5561
github.com/Microsoft/go-winio v0.6.2 // indirect
5662
github.com/andygrunwald/go-jira v1.16.0 // indirect
5763
github.com/btcsuite/btcd v0.24.2 // indirect
58-
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
59-
github.com/btcsuite/btcd/btcutil v1.1.6 // indirect
6064
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
6165
github.com/btcsuite/btclog v0.0.0-20241017175713-3428138b75c7 // indirect
6266
github.com/bwesterb/go-ristretto v1.2.3 // indirect
@@ -73,7 +77,6 @@ require (
7377
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
7478
github.com/deso-protocol/go-deadlock v1.0.1 // indirect
7579
github.com/deso-protocol/go-merkle-tree v1.0.0 // indirect
76-
github.com/deso-protocol/uint256 v1.3.2 // indirect
7780
github.com/dgraph-io/badger/v3 v3.2103.5 // indirect
7881
github.com/dgraph-io/ristretto v0.2.0 // indirect
7982
github.com/dustin/go-humanize v1.0.1 // indirect
@@ -110,7 +113,6 @@ require (
110113
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect
111114
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
112115
github.com/hashicorp/go-sockaddr v1.0.7 // indirect
113-
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
114116
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
115117
github.com/holiman/uint256 v1.3.1 // indirect
116118
github.com/huandu/xstrings v1.5.0 // indirect
@@ -121,7 +123,7 @@ require (
121123
github.com/kevinburke/go-types v0.0.0-20240719050749-165e75e768f7 // indirect
122124
github.com/kevinburke/rest v0.0.0-20240617045629-3ed0ad3487f0 // indirect
123125
github.com/kevinburke/twilio-go v0.0.0-20240716172313-813590983ccc // indirect
124-
github.com/klauspost/compress v1.17.1 // indirect
126+
github.com/klauspost/compress v1.17.11 // indirect
125127
github.com/kyokomi/emoji/v2 v2.2.13 // indirect
126128
github.com/magiconair/properties v1.8.7 // indirect
127129
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -161,15 +163,13 @@ require (
161163
github.com/spf13/cast v1.7.0 // indirect
162164
github.com/spf13/cobra v1.8.1 // indirect
163165
github.com/spf13/pflag v1.0.5 // indirect
164-
github.com/stretchr/testify v1.9.0 // indirect
165166
github.com/subosito/gotenv v1.6.0 // indirect
166167
github.com/tinylib/msgp v1.2.2 // indirect
167168
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
168169
github.com/trivago/tgo v1.0.7 // indirect
169170
github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect
170171
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
171172
github.com/ttacon/libphonenumber v1.2.1 // indirect
172-
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
173173
github.com/unrolled/secure v1.17.0 // indirect
174174
github.com/urfave/cli/v2 v2.27.5 // indirect
175175
github.com/vmihailenco/bufpool v0.1.11 // indirect
@@ -188,16 +188,16 @@ require (
188188
go.opentelemetry.io/otel/trace v1.31.0 // indirect
189189
go.uber.org/atomic v1.11.0 // indirect
190190
go.uber.org/multierr v1.11.0 // indirect
191-
golang.org/x/crypto v0.28.0 // indirect
191+
golang.org/x/crypto v0.29.0 // indirect
192192
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
193193
golang.org/x/image v0.21.0 // indirect
194194
golang.org/x/mod v0.21.0 // indirect
195-
golang.org/x/net v0.30.0 // indirect
195+
golang.org/x/net v0.31.0 // indirect
196196
golang.org/x/oauth2 v0.23.0 // indirect
197-
golang.org/x/sync v0.8.0 // indirect
198-
golang.org/x/sys v0.26.0 // indirect
199-
golang.org/x/term v0.25.0 // indirect
200-
golang.org/x/text v0.19.0 // indirect
197+
golang.org/x/sync v0.9.0 // indirect
198+
golang.org/x/sys v0.27.0 // indirect
199+
golang.org/x/term v0.26.0 // indirect
200+
golang.org/x/text v0.20.0 // indirect
201201
golang.org/x/time v0.7.0 // indirect
202202
golang.org/x/tools v0.26.0 // indirect
203203
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
317317
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
318318
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
319319
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
320-
github.com/klauspost/compress v1.17.1 h1:NE3C767s2ak2bweCZo3+rdP4U/HoyVXLv/X9f2gPS5g=
321-
github.com/klauspost/compress v1.17.1/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
320+
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
321+
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
322322
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
323323
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
324324
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -464,8 +464,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
464464
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
465465
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
466466
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
467-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
468-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
467+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
468+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
469469
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
470470
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
471471
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
@@ -549,8 +549,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
549549
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
550550
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
551551
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
552-
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
553-
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
552+
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
553+
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
554554
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
555555
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
556556
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
@@ -585,8 +585,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
585585
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
586586
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
587587
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
588-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
589-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
588+
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
589+
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
590590
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
591591
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
592592
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
@@ -599,8 +599,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
599599
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
600600
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
601601
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
602-
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
603-
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
602+
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
603+
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
604604
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
605605
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
606606
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -632,25 +632,25 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
632632
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
633633
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
634634
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
635-
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
636-
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
635+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
636+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
637637
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
638638
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
639639
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
640640
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
641641
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
642642
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
643-
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
644-
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
643+
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
644+
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
645645
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
646646
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
647647
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
648648
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
649649
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
650650
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
651651
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
652-
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
653-
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
652+
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
653+
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
654654
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
655655
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
656656
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

handler/data_handler.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"database/sql"
77
"encoding/hex"
88
"fmt"
9+
910
"github.com/deso-protocol/core/lib"
1011
"github.com/deso-protocol/postgres-data-handler/entries"
1112
"github.com/deso-protocol/postgres-data-handler/migrations/post_sync_migrations"
@@ -32,7 +33,7 @@ type PostgresDataHandler struct {
3233
}
3334

3435
// HandleEntryBatch performs a bulk operation for a batch of entries, based on the encoder type.
35-
func (postgresDataHandler *PostgresDataHandler) HandleEntryBatch(batchedEntries []*lib.StateChangeEntry) error {
36+
func (postgresDataHandler *PostgresDataHandler) HandleEntryBatch(batchedEntries []*lib.StateChangeEntry, isMempool bool) error {
3637
if len(batchedEntries) == 0 {
3738
return fmt.Errorf("PostgresDataHandler.HandleEntryBatch: No entries currently batched.")
3839
}
@@ -227,6 +228,19 @@ func (postgresDataHandler *PostgresDataHandler) CommitTransaction() error {
227228
return errors.Wrapf(err, "PostgresDataHandler.CommitTransaction: Error committing transaction")
228229
}
229230
postgresDataHandler.Txn = nil
231+
232+
// Call the post-transaction commit hook
233+
if err := postgresDataHandler.CallPostTransactionCommitHook(); err != nil {
234+
return errors.Wrapf(err, "PostgresDataHandler.CommitTransaction: Error calling post-transaction commit hook")
235+
}
236+
237+
return nil
238+
}
239+
240+
func (postgresDataHandler *PostgresDataHandler) CallPostTransactionCommitHook() error {
241+
if err := CallPostgresFunction(postgresDataHandler.DB, "on_pdh_pg_txn_committed"); err != nil {
242+
return errors.Wrapf(err, "PostgresDataHandler.CallPostTransactionCommitHook: Error calling post-transaction commit hook")
243+
}
230244
return nil
231245
}
232246

handler/db_utils.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package handler
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
7+
58
"github.com/deso-protocol/postgres-data-handler/migrations/initial_migrations"
69
"github.com/deso-protocol/postgres-data-handler/migrations/post_sync_migrations"
710
"github.com/golang/glog"
11+
"github.com/pkg/errors"
812
"github.com/uptrace/bun"
913
"github.com/uptrace/bun/migrate"
1014
)
@@ -80,3 +84,27 @@ func RollbackAllMigrations(migrator *migrate.Migrator, ctx context.Context) erro
8084
}
8185
return nil
8286
}
87+
88+
// CallPostgresFunction executes a PostgreSQL function with the given name and parameters.
89+
// It returns any error encountered during execution.
90+
func CallPostgresFunction(db *bun.DB, functionName string, params ...interface{}) error {
91+
// Build the function call SQL
92+
var sqlFunction string
93+
if len(params) == 0 {
94+
sqlFunction = fmt.Sprintf("SELECT %s();", functionName)
95+
} else {
96+
// Create placeholders for parameters ($1, $2, etc.)
97+
placeholders := make([]string, len(params))
98+
for i := range placeholders {
99+
placeholders[i] = fmt.Sprintf("$%d", i+1)
100+
}
101+
sqlFunction = fmt.Sprintf("SELECT %s(%s);", functionName, strings.Join(placeholders, ", "))
102+
}
103+
104+
// Execute the function
105+
_, err := db.ExecContext(context.Background(), sqlFunction, params...)
106+
if err != nil {
107+
return errors.Wrapf(err, "CallPostgresFunction: Error calling function %s", functionName)
108+
}
109+
return nil
110+
}

local.docker-compose.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ services:
2626
# - SYNC_TYPE=hypersync
2727
# - HYPERSYNC=true
2828
# Blocksync Settings:
29-
- SYNC_TYPE=blocksync
30-
- HYPERSYNC=false
29+
# - SYNC_TYPE=blocksync
30+
# - HYPERSYNC=false
3131

3232
# Mainnet Settings:
3333
# - REGTEST=false
@@ -36,23 +36,23 @@ services:
3636
# - STATE_CHANGE_DIR=/ss/state-changes
3737

3838
# Testnet Settings:
39-
- REGTEST=false
40-
- TESTNET=true
41-
- CONNECT_IPS=35.192.117.201:18000
42-
- STATE_CHANGE_DIR=/ss/state-changes
43-
- TRUSTED_BLOCK_PRODUCER_PUBLIC_KEYS=
44-
- TRUSTED_BLOCK_PRODUCER_START_HEIGHT=10000000
39+
# - REGTEST=false
40+
# - TESTNET=true
41+
# - CONNECT_IPS=35.192.117.201:18000
42+
# - STATE_CHANGE_DIR=/ss/state-changes
43+
# - TRUSTED_BLOCK_PRODUCER_PUBLIC_KEYS=
44+
# - TRUSTED_BLOCK_PRODUCER_START_HEIGHT=10000000
4545

4646
# Regtest Settings:
47-
# - REGTEST=true
48-
# - TESTNET=true
49-
# - STATE_CHANGE_DIR=/ss/state-changes
50-
# - ADMIN_PUBLIC_KEYS=*
51-
# - SUPER_ADMIN_PUBLIC_KEYS=*
52-
# - NUM_MINING_THREADS=1
53-
# - MINER_PUBLIC_KEYS=BC1YLg7Bk5sq9iNY17bAwoAYiChLYpmWEi6nY6q5gnA1UQV6xixHjfV
54-
# - BLOCK_PRODUCER_SEED=essence camp ghost remove document vault ladder swim pupil index apart ring
55-
# - STARTER_DESO_SEED=road congress client market couple bid risk escape artwork rookie artwork food
47+
- REGTEST=true
48+
- TESTNET=true
49+
- STATE_CHANGE_DIR=/ss/state-changes
50+
- ADMIN_PUBLIC_KEYS=*
51+
- SUPER_ADMIN_PUBLIC_KEYS=*
52+
- NUM_MINING_THREADS=1
53+
- MINER_PUBLIC_KEYS=BC1YLg7Bk5sq9iNY17bAwoAYiChLYpmWEi6nY6q5gnA1UQV6xixHjfV
54+
- BLOCK_PRODUCER_SEED=essence camp ghost remove document vault ladder swim pupil index apart ring
55+
- STARTER_DESO_SEED=road congress client market couple bid risk escape artwork rookie artwork food
5656
ports:
5757
- '18000:18000'
5858
- '18001:18001'

0 commit comments

Comments
 (0)