prysm-pulse/beacon-chain/blockchain/mock_test.go

31 lines
974 B
Go
Raw Normal View History

Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
package blockchain
import (
"testing"
testDB "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing"
doublylinkedtree "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/doubly-linked-tree"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/startup"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen"
Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
)
func testServiceOptsWithDB(t *testing.T) []Option {
beaconDB := testDB.SetupDB(t)
fcs := doublylinkedtree.New()
Replace statefeed Initialize (#12285) * refactor initialization to blocking startup method * require genesisSetter in blockchain, fix tests * work-around gazelle weirdness * fix dep gazelle ignores * only call SetGenesis once * fix typo * validator test setup and fix to return right error * move waitForChainStart to Start * wire up sync Service.genesisWaiter * fix p2p genesisWaiter plumbing * remove extra clock type, integrate into genesis and rename * use time.Now when no Nower is specified * remove unused ClockSetter * simplify rpc context checking * fix typo * use clock everywhere in sync; [32]byte val root * don't use DeepEqual to compare [32]byte and []byte * don't use clock in init sync, not wired up yet * use clock waiter in blockchain as well * use cancelable contexts in tests with goroutines * missed a reference to WithClockSetter * Update beacon-chain/startup/genesis.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/blockchain/service_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * more clear docs * doc for NewClock * move clock typedef to more logical file name * adding documentation * gaz * fixes for capella * reducing test raciness * fix races in committee cache tests * lint * add tests on Duration slot math helper * startup package test coverage * fix bad merge * set non-zero genesis time in tests that call Start * happy deepsource, happy me-epsource * replace Synced event with channel * remove unused error * remove accidental wip commit * gaz! * remove unused event constants * remove sync statefeed subscription to fix deadlock * remove state notifier * fix build --------- Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
2023-05-03 04:34:01 +00:00
cs := startup.NewClockSynchronizer()
Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
return []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB, fcs)),
Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
WithForkChoiceStore(fcs),
Replace statefeed Initialize (#12285) * refactor initialization to blocking startup method * require genesisSetter in blockchain, fix tests * work-around gazelle weirdness * fix dep gazelle ignores * only call SetGenesis once * fix typo * validator test setup and fix to return right error * move waitForChainStart to Start * wire up sync Service.genesisWaiter * fix p2p genesisWaiter plumbing * remove extra clock type, integrate into genesis and rename * use time.Now when no Nower is specified * remove unused ClockSetter * simplify rpc context checking * fix typo * use clock everywhere in sync; [32]byte val root * don't use DeepEqual to compare [32]byte and []byte * don't use clock in init sync, not wired up yet * use clock waiter in blockchain as well * use cancelable contexts in tests with goroutines * missed a reference to WithClockSetter * Update beacon-chain/startup/genesis.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/blockchain/service_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * more clear docs * doc for NewClock * move clock typedef to more logical file name * adding documentation * gaz * fixes for capella * reducing test raciness * fix races in committee cache tests * lint * add tests on Duration slot math helper * startup package test coverage * fix bad merge * set non-zero genesis time in tests that call Start * happy deepsource, happy me-epsource * replace Synced event with channel * remove unused error * remove accidental wip commit * gaz! * remove unused event constants * remove sync statefeed subscription to fix deadlock * remove state notifier * fix build --------- Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
2023-05-03 04:34:01 +00:00
WithClockSynchronizer(cs),
Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
}
}
// WARNING: only use these opts when you are certain there are no db calls
Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
// in your code path. this is a lightweight way to satisfy the stategen/beacondb
// initialization requirements w/o the overhead of db init.
func testServiceOptsNoDB() []Option {
Replace statefeed Initialize (#12285) * refactor initialization to blocking startup method * require genesisSetter in blockchain, fix tests * work-around gazelle weirdness * fix dep gazelle ignores * only call SetGenesis once * fix typo * validator test setup and fix to return right error * move waitForChainStart to Start * wire up sync Service.genesisWaiter * fix p2p genesisWaiter plumbing * remove extra clock type, integrate into genesis and rename * use time.Now when no Nower is specified * remove unused ClockSetter * simplify rpc context checking * fix typo * use clock everywhere in sync; [32]byte val root * don't use DeepEqual to compare [32]byte and []byte * don't use clock in init sync, not wired up yet * use clock waiter in blockchain as well * use cancelable contexts in tests with goroutines * missed a reference to WithClockSetter * Update beacon-chain/startup/genesis.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/blockchain/service_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * more clear docs * doc for NewClock * move clock typedef to more logical file name * adding documentation * gaz * fixes for capella * reducing test raciness * fix races in committee cache tests * lint * add tests on Duration slot math helper * startup package test coverage * fix bad merge * set non-zero genesis time in tests that call Start * happy deepsource, happy me-epsource * replace Synced event with channel * remove unused error * remove accidental wip commit * gaz! * remove unused event constants * remove sync statefeed subscription to fix deadlock * remove state notifier * fix build --------- Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
2023-05-03 04:34:01 +00:00
cs := startup.NewClockSynchronizer()
return []Option{WithClockSynchronizer(cs)}
Switch to lazy state balance cache (#9822) * quick lazy balance cache proof of concept * WIP refactoring to use lazy cache * updating tests to use functional opts * updating the rest of the tests, all passing * use mock stategen where possible reduces the number of test cases that require db setup * rename test opt method for clear link * Update beacon-chain/blockchain/process_block.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * test assumption that zerohash is in db * remove unused MockDB (mocking stategen instead) * fix cache bug, switch to sync.Mutex * improve test coverage for the state cache * uncomment failing genesis test for discussion * gofmt * remove unused Service struct member * cleanup unused func input * combining type declaration in signature * don't export the state cache constructor * work around blockchain deps w/ new file service_test brings in a ton of dependencies that make bazel rules for blockchain complex, so just sticking these mocks in their own file simplifies things. * gofmt * remove intentionally failing test this test established that the zero root can't be used to look up the state, resulting in a change in another PR to update stategen to use the GenesisState db method instead when the zero root is detected. * fixed error introduced by develop refresh * fix import ordering * appease deepsource * remove unused function * godoc comments on new requires/assert * defensive constructor per terence's PR comment * more differentiated balance cache metric names Co-authored-by: kasey <kasey@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-11-19 15:59:26 +00:00
}