Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9a4e65d
updates to support no longer having best chain
lazynina Oct 7, 2024
07e97a9
trigger build
lazynina Oct 8, 2024
a98ea46
go mod tidy and upgrade some deps
lazynina Oct 8, 2024
b1d99c5
fix bimg max size
lazynina Oct 8, 2024
4a7328f
trigger build with SetBestChain set to public
lazynina Oct 8, 2024
26603fc
trigger build
lazynina Oct 8, 2024
001a5de
trigger build
lazynina Oct 8, 2024
bc1bcef
trigger build again
lazynina Oct 8, 2024
b849278
trigger build w/ fix
lazynina Oct 8, 2024
f487310
trigger build w/ using get block from best chain by hash again
lazynina Oct 8, 2024
aca06c9
trigger build with small enhancements to get block from best chain by…
lazynina Oct 9, 2024
d494ba1
trigger build w/ early exit for header validated in get from best cha…
lazynina Oct 9, 2024
f85eb03
trigger build w/ txindex fix
lazynina Oct 9, 2024
8194c9b
trigger build w/ txindex fix
lazynina Oct 9, 2024
ba30372
trigger build w/ removal of heal orphan pointers
lazynina Oct 9, 2024
3f52038
Merge branch 'main' into ln/replace-best-chain-with-block-index
lazynina Oct 10, 2024
3fba557
merge in main
lazynina Dec 5, 2024
dd3c46f
trigger build
lazynina Dec 5, 2024
474a2a2
Trigger build again with locator stuff removed
lazynina Dec 5, 2024
d6d2d92
trigger build w/ smaller block index cache size
lazynina Dec 5, 2024
6e5ddee
trigger build again
lazynina Dec 5, 2024
6e87091
trigger build again
lazynina Dec 5, 2024
3cced79
Trigger build again
lazynina Dec 5, 2024
40571c1
Trigger build
lazynina Dec 5, 2024
06f8e26
trigger build w/ reverse iteration over block nodes
lazynina Dec 5, 2024
161684d
trigger build
lazynina Dec 6, 2024
25a732c
trigger build again
lazynina Dec 9, 2024
9ccfbc6
updates to support calling hash less often
lazynina Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.28.0
golang.org/x/crypto v0.29.0
golang.org/x/image v0.21.0
golang.org/x/sync v0.8.0
golang.org/x/sync v0.9.0
google.golang.org/api v0.201.0
gopkg.in/DataDog/dd-trace-go.v1 v1.69.0
)
Expand Down Expand Up @@ -78,7 +78,6 @@ require (
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/decred/dcrd/container/lru v1.0.0 // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
github.com/deso-protocol/go-merkle-tree v1.0.0 // indirect
github.com/dgraph-io/ristretto v0.2.0 // indirect
Expand Down Expand Up @@ -123,7 +122,7 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kevinburke/go-types v0.0.0-20240719050749-165e75e768f7 // indirect
github.com/kevinburke/rest v0.0.0-20240617045629-3ed0ad3487f0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/kyokomi/emoji/v2 v2.2.13 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -181,11 +180,11 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
Expand Down
34 changes: 16 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/container/lru v1.0.0 h1:7foQymtbu18aQWYiY9RnNIeE+kvpiN+fiBQ3+viyJjI=
github.com/decred/dcrd/container/lru v1.0.0/go.mod h1:vlPwj0l+IzAHhQSsbgQnJgO5Cte78+yI065V+Mc5PRQ=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
Expand Down Expand Up @@ -317,8 +315,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.17.1 h1:NE3C767s2ak2bweCZo3+rdP4U/HoyVXLv/X9f2gPS5g=
github.com/klauspost/compress v1.17.1/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down Expand Up @@ -461,8 +459,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
Expand Down Expand Up @@ -536,8 +534,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
Expand Down Expand Up @@ -572,8 +570,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
Expand All @@ -586,8 +584,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -619,25 +617,25 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
16 changes: 12 additions & 4 deletions routes/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ func (fes *APIServer) getTxindexMetadataForUncommittedBlock(
uncommittedTxnMetaMap := make(map[lib.BlockHash]*lib.TransactionMetadata)
txindexUtxoView := lib.NewUtxoView(fes.blockchain.DB(), fes.Params, nil, nil, nil)
if blockNode.Header.PrevBlockHash != nil && !txindexUtxoView.TipHash.IsEqual(blockNode.Header.PrevBlockHash) {
utxoViewAndUtxoOps, err := fes.blockchain.GetUtxoViewAndUtxoOpsAtBlockHash(*blockNode.Header.PrevBlockHash)
utxoViewAndUtxoOps, err := fes.blockchain.GetUtxoViewAndUtxoOpsAtBlockHash(*blockNode.Header.PrevBlockHash, blockNode.Header.Height-1)
if err != nil {
return nil, errors.Wrap(err,
"getTxindexMetadataForUncommittedBlock: Problem fetching utxoView for uncommitted block")
Expand Down Expand Up @@ -1398,7 +1398,7 @@ func (fes *APIServer) APIBlock(ww http.ResponseWriter, rr *http.Request) {

// For this endpoint we need to lock the blockchain for reading.
// If the HashHex is set, look the block up using that.
numBlocks := len(fes.blockchain.BestChain())
numBlocks := fes.blockchain.BlockTip().Height + 1

var blockNode *lib.BlockNode
var blockHash *lib.BlockHash
Expand All @@ -1420,15 +1420,23 @@ func (fes *APIServer) APIBlock(ww http.ResponseWriter, rr *http.Request) {
} else {
// Find the block node with the corresponding height on the best chain.
if blockRequest.Height >= int64(numBlocks) || blockRequest.Height < 0 {
maxHeight := len(fes.blockchain.BestChain()) - 1
maxHeight := fes.blockchain.BlockTip().Height

APIAddError(ww, fmt.Sprintf("APIBlockRequest: Height requested "+
"%d must be >= 0 and <= "+
"height of best block chain tip %d", blockRequest.Height,
maxHeight))
return
}
blockNode = fes.blockchain.BestChain()[blockRequest.Height]
blockNode, exists, err := fes.blockchain.GetBlockFromBestChainByHeight(uint64(blockRequest.Height), false)
if err != nil {
APIAddError(ww, fmt.Sprintf("APIBlockRequest: Problem fetching block: %v", err))
return
}
if !exists {
APIAddError(ww, fmt.Sprintf("APIBlockRequest: Block with height %d not found", blockRequest.Height))
return
}
blockHash = blockNode.Hash
}

Expand Down
38 changes: 28 additions & 10 deletions routes/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"github.com/deso-protocol/core/collections"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -146,6 +147,13 @@ func NewLowDifficultyBlockchainWithParams(t *testing.T, params *lib.DeSoParams)
return chain, &paramsCopy, db, dir
}

func GetBlockFromBestChainByHeight(t *testing.T, blockchain *lib.Blockchain, height uint32) *lib.BlockNode {
blockNode, exists, err := blockchain.GetBlockFromBestChainByHeight(uint64(height), false)
require.NoError(t, err)
require.True(t, exists)
return blockNode
}

func NewTestMiner(t *testing.T, chain *lib.Blockchain, params *lib.DeSoParams, isSender bool) (*lib.DeSoMempool, *lib.DeSoMiner) {
assert := assert.New(t)
require := require.New(t)
Expand Down Expand Up @@ -595,16 +603,18 @@ func TestAPI(t *testing.T) {
}
assert.Equal("", transactionInfoRes.Error)
assert.Equal(2, len(transactionInfoRes.Transactions))
block1 := GetBlockFromBestChainByHeight(t, apiServer.blockchain, 1)
block2 := GetBlockFromBestChainByHeight(t, apiServer.blockchain, 2)
assert.Contains(
[]string{
hex.EncodeToString(apiServer.blockchain.BestChain()[1].Hash[:]),
hex.EncodeToString(apiServer.blockchain.BestChain()[2].Hash[:]),
hex.EncodeToString(block1.Hash[:]),
hex.EncodeToString(block2.Hash[:]),
},
transactionInfoRes.Transactions[0].BlockHashHex)
assert.Contains(
[]string{
hex.EncodeToString(apiServer.blockchain.BestChain()[1].Hash[:]),
hex.EncodeToString(apiServer.blockchain.BestChain()[2].Hash[:]),
hex.EncodeToString(block1.Hash[:]),
hex.EncodeToString(block2.Hash[:]),
},
transactionInfoRes.Transactions[1].BlockHashHex)
assert.Equal(0, len(transactionInfoRes.Transactions[0].Inputs))
Expand All @@ -614,10 +624,10 @@ func TestAPI(t *testing.T) {
var firstBlockTxn *lib.MsgDeSoTxn
var secondBlockTxn *lib.MsgDeSoTxn
{
blockHash := apiServer.blockchain.BestChain()[1].Hash
blockHash := GetBlockFromBestChainByHeight(t, apiServer.blockchain, 1).Hash
blockLookup, err := lib.GetBlock(blockHash, apiServer.blockchain.DB(), apiServer.blockchain.Snapshot())
require.NoError(err)
block2Lookup, err := lib.GetBlock(apiServer.blockchain.BestChain()[2].Hash, apiServer.blockchain.DB(), apiServer.blockchain.Snapshot())
block2Lookup, err := lib.GetBlock(GetBlockFromBestChainByHeight(t, apiServer.blockchain, 2).Hash, apiServer.blockchain.DB(), apiServer.blockchain.Snapshot())

firstBlockTxn = blockLookup.Txns[0]
secondBlockTxn = block2Lookup.Txns[0]
Expand All @@ -643,7 +653,7 @@ func TestAPI(t *testing.T) {
assert.Equal(1, len(transactionInfoRes.Transactions))
assert.Contains(
[]string{
hex.EncodeToString(apiServer.blockchain.BestChain()[1].Hash[:]),
hex.EncodeToString(GetBlockFromBestChainByHeight(t, apiServer.blockchain, 1).Hash[:]),
},
transactionInfoRes.Transactions[0].BlockHashHex)
assert.Equal(0, len(transactionInfoRes.Transactions[0].Inputs))
Expand Down Expand Up @@ -1335,8 +1345,16 @@ func TestAPI(t *testing.T) {

// Set the tip to the first block and make sure all txns get deleted.
{
chainWithFirstBlockOnly := apiServer.blockchain.BestChain()[:2]
oldBestChain := apiServer.blockchain.BestChain()
block0 := GetBlockFromBestChainByHeight(t, apiServer.blockchain, 0)
block1 := GetBlockFromBestChainByHeight(t, apiServer.blockchain, 1)
chainWithFirstBlockOnly := []*lib.BlockNode{block0, block1}
oldBestChainTip := apiServer.blockchain.BlockTip()
oldBestChain := []*lib.BlockNode{}
for oldBestChainTip != nil {
oldBestChain = append(oldBestChain, oldBestChainTip)
oldBestChainTip = oldBestChainTip.GetParent(apiServer.blockchain.GetBlockIndex())
}
oldBestChain = collections.Reverse(oldBestChain)
apiServer.blockchain.SetBestChain(chainWithFirstBlockOnly)
require.NoError(apiServer.TXIndex.Update())

Expand Down Expand Up @@ -1391,7 +1409,7 @@ func TestAPI(t *testing.T) {
assert.Equal(1, len(transactionInfoRes.Transactions))
assert.Contains(
[]string{
hex.EncodeToString(apiServer.blockchain.BestChain()[1].Hash[:]),
hex.EncodeToString(GetBlockFromBestChainByHeight(t, apiServer.blockchain, 1).Hash[:]),
},
transactionInfoRes.Transactions[0].BlockHashHex)
assert.Equal(0, len(transactionInfoRes.Transactions[0].Inputs))
Expand Down
19 changes: 8 additions & 11 deletions routes/hot_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,11 @@ func (fes *APIServer) UpdateHotFeedOrderedList(

// This offset allows us to see what the hot feed would look like in the past,
// which is useful for testing purposes.
blockOffsetForTesting := 0
// TODO: this is a little more annoying to support without the full history of best chain.
// we can revisit implementing later if needed. Just takes a few more minutes.
// blockOffsetForTesting := 0

lookbackWindowBlocks := LookbackWindowBlocks
// Check if the most recent blocks that we'll be considering in hot feed computation have been processed.
for _, blockNode := range fes.blockchain.BestChain() {
if blockNode.Height < blockTip.Height-uint32(lookbackWindowBlocks+blockOffsetForTesting) {
continue
}
}

// Log how long this routine takes, since it could be heavy.
glog.V(2).Info("UpdateHotFeedOrderedList: Starting new update cycle.")
Expand All @@ -425,10 +421,11 @@ func (fes *APIServer) UpdateHotFeedOrderedList(
}

// Grab the last 24 hours worth of blocks (288 blocks @ 5min/block).
blockTipIndex := len(fes.blockchain.BestChain()) - 1 - blockOffsetForTesting
relevantNodes := fes.blockchain.BestChain()
if len(fes.blockchain.BestChain()) > (lookbackWindowBlocks + blockOffsetForTesting) {
relevantNodes = fes.blockchain.BestChain()[blockTipIndex-lookbackWindowBlocks-blockOffsetForTesting : blockTipIndex]
startNode := fes.blockchain.BlockTip()
relevantNodes := []*lib.BlockNode{}
for len(relevantNodes) < lookbackWindowBlocks && startNode != nil {
relevantNodes = append(relevantNodes, startNode)
startNode = startNode.GetParent(fes.blockchain.GetBlockIndex())
}

var hotnessInfoBlocks []*HotnessInfoBlock
Expand Down
2 changes: 1 addition & 1 deletion routes/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (fes *APIServer) SubmitBlock(ww http.ResponseWriter, req *http.Request) {
// The optimal solution is to check signatures in a way that doesn't acquire the
// ChainLock, which is what Bitcoin Core does.
isMainChain, isOrphan, _, err := fes.blockchain.ProcessBlock(
blockFound, true /*verifySignatures*/)
blockFound, nil, true /*verifySignatures*/)
glog.V(1).Infof("Called ProcessBlock/ConnectBlock: isMainChain=(%v), isOrphan=(%v), err=(%v)",
isMainChain, isOrphan, err)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions routes/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4553,9 +4553,9 @@ func (fes *APIServer) GetTxnConstructionParams(ww http.ResponseWriter, req *http
func (fes *APIServer) GetCommittedTipBlockInfo(ww http.ResponseWriter, req *http.Request) {
// Get the block tip from the blockchain.
fes.backendServer.GetBlockchain().ChainLock.RLock()
blockTip, idx := fes.backendServer.GetBlockchain().GetCommittedTip()
blockTip, exists := fes.backendServer.GetBlockchain().GetCommittedTip()
fes.backendServer.GetBlockchain().ChainLock.RUnlock()
if idx == -1 {
if !exists {
_AddBadRequestError(ww, "GetCommittedTipBlockInfo: Problem getting block tip")
return
}
Expand Down
Loading