Closed rusttech closed 1 day ago
The changes in this pull request involve a modification to the GetConsensusValidators
method within the Database
struct located in server/database.go
. The primary adjustment is the way the validators
slice is initialized. Instead of pre-allocating the slice with a fixed length equal to the number of validators, it is now initialized with both a length and capacity of zero, allowing for dynamic growth as entries are added. This optimizes memory usage while maintaining the existing logic of the method.
File | Change Summary |
---|---|
server/database.go | Modified GetConsensusValidators method to initialize validators slice with zero length and capacity for dynamic growth. |
server/database_test.go | Updated TestGetConsensusValidators method to change expected length of validators slice from 2 to 1. |
In the server's quiet space,
A slice now finds its place.
With zero length, it starts anew,
Growing strong with each value true.
Memory saved, a gentle cheer,
For validators, we hold dear! 🐇✨
@rusttech Could you please fix the TestGetConsensusValidators test? The expected validators length should be 1.
@rusttech Could you please fix the TestGetConsensusValidators test? The expected validators length should be 1.
Of course. Modified.
Please review again.
The intention here should be to initialize a slice with a capacity of
len(state.Validators.Validators)
rather than initializing the length of this slice.The online demo: https://go.dev/play/p/q1BcVCmvidW
Summary by CodeRabbit