Skip to content

Remove latestBeaconBlockRoot from BeaconState #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class QbftBlockCreator(
).get()
val stateRoot =
HashUtil.stateRoot(
BeaconState(stateRootBlockHeader, HashUtil.bodyRoot(beaconBlockBody), validators),
BeaconState(stateRootBlockHeader, validators),
)
val finalBlockHeader = stateRootBlockHeader.copy(stateRoot = stateRoot)
val beaconBlock =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package maru.consensus.state
import maru.consensus.ValidatorProvider
import maru.core.BeaconBlock
import maru.core.BeaconState
import maru.serialization.rlp.bodyRoot
import tech.pegasys.teku.infrastructure.async.SafeFuture

fun interface StateTransition {
Expand All @@ -33,7 +32,6 @@ class StateTransitionImpl(
return validatorsForBlockFuture.thenApply { validatorsForBlock ->
BeaconState(
latestBeaconBlockHeader = block.beaconBlockHeader,
latestBeaconBlockRoot = block.beaconBlockHeader.bodyRoot,
validators = validatorsForBlock,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class QbftBlockCreatorTest {
HashUtil.stateRoot(
BeaconState(
createBeaconBlock.beaconBlockHeader.copy(stateRoot = BeaconBlockHeader.EMPTY_STATE_ROOT),
HashUtil.bodyRoot(createBeaconBlock.beaconBlockBody),
Collections.emptySet(),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ package maru.consensus.state

import maru.consensus.ValidatorProvider
import maru.core.BeaconState
import maru.core.HashUtil
import maru.core.ext.DataGenerators
import maru.serialization.rlp.bodyRoot
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.eq
Expand All @@ -35,7 +33,6 @@ class StateTransitionImplTest {
val expectedPostState =
BeaconState(
latestBeaconBlockHeader = newBlock.beaconBlockHeader,
latestBeaconBlockRoot = HashUtil.bodyRoot(newBlock.beaconBlockBody),
validators = validators,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class BlockValidatorTest {
private val currBeaconState =
BeaconState(
latestBeaconBlockHeader = validCurrBlockHeader,
latestBeaconBlockRoot = validCurrBlockHeader.bodyRoot,
validators = validators.toSet(),
)

Expand All @@ -81,7 +80,6 @@ class BlockValidatorTest {
HashUtil.stateRoot(
BeaconState(
latestBeaconBlockHeader = validNewBlockStateRootHeader,
latestBeaconBlockRoot = validNewBlockStateRootHeader.bodyRoot,
validators = validators.toSet(),
),
)
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/kotlin/maru/core/BeaconState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package maru.core
*/
data class BeaconState(
val latestBeaconBlockHeader: BeaconBlockHeader,
val latestBeaconBlockRoot: ByteArray,
val validators: Set<Validator>,
) {
override fun equals(other: Any?): Boolean {
Expand All @@ -32,15 +31,13 @@ data class BeaconState(
other as BeaconState

if (latestBeaconBlockHeader != other.latestBeaconBlockHeader) return false
if (!latestBeaconBlockRoot.contentEquals(other.latestBeaconBlockRoot)) return false
if (validators != other.validators) return false

return true
}

override fun hashCode(): Int {
var result = latestBeaconBlockHeader.hashCode()
result = 31 * result + latestBeaconBlockRoot.contentHashCode()
result = 31 * result + validators.hashCode()
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ object DataGenerators {
)
return BeaconState(
latestBeaconBlockHeader = beaconBlockHeader,
latestBeaconBlockRoot = Random.nextBytes(32),
validators = buildSet(3) { Validator(Random.nextBytes(128)) },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package maru.serialization.rlp

import maru.core.BeaconState
import org.apache.tuweni.bytes.Bytes
import org.hyperledger.besu.ethereum.rlp.RLPInput
import org.hyperledger.besu.ethereum.rlp.RLPOutput

Expand All @@ -31,7 +30,6 @@ class BeaconStateSerializer(
rlpOutput.startList()

beaconBlockHeaderSerializer.writeTo(value.latestBeaconBlockHeader, rlpOutput)
rlpOutput.writeBytes(Bytes.wrap(value.latestBeaconBlockRoot))
rlpOutput.writeList(value.validators) { validator, output ->
validatorSerializer.writeTo(validator, output)
}
Expand All @@ -43,14 +41,12 @@ class BeaconStateSerializer(
rlpInput.enterList()

val latestBeaconBlockHeader = beaconBlockHeaderSerializer.readFrom(rlpInput)
val latestBeaconBlockRoot = rlpInput.readBytes().toArray()
val validators = rlpInput.readList { validatorSerializer.readFrom(it) }.toSet()

rlpInput.leaveList()

return BeaconState(
latestBeaconBlockHeader = latestBeaconBlockHeader,
latestBeaconBlockRoot = latestBeaconBlockRoot,
validators = validators,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class BeaconStateSerializerTest {
val testValue =
BeaconState(
latestBeaconBlockHeader = beaconBLockHeader,
latestBeaconBlockRoot = Random.nextBytes(32),
validators = buildSet(3) { Validator(Random.nextBytes(128)) },
)
val serializedData = serializer.serialize(testValue)
Expand Down
Loading