Skip to content

Commit

Permalink
clean up dummy roothash message types
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Oct 9, 2019
1 parent 6018635 commit 45dbf40
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
12 changes: 0 additions & 12 deletions go/roothash/api/block/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ const (
Decrease AdjustmentOp = 2
)

// DummyRoothashMessage is a no-effect message for testing.
// Mux app in charge: staking
type DummyRoothashMessage struct {
Greeting string `json:"greeting"`
}

// DummyRejectRoothashMessage is a message for testing that causes staking not to be satisfied.
// Mux app in charge: staking
type DummyRejectRoothashMessage struct{}

// StakingGeneralAdjustmentRoothashMessage is a message that changes an account's general balance.
// Mux app in charge: staking
type StakingGeneralAdjustmentRoothashMessage struct {
Expand All @@ -67,8 +57,6 @@ type StakingGeneralAdjustmentRoothashMessage struct {

// RoothashMessage is a roothash message.
type RoothashMessage struct {
DummyRoothashMessage *DummyRoothashMessage
DummyRejectRoothashMessage *DummyRejectRoothashMessage
StakingGeneralAdjustmentRoothashMessage *StakingGeneralAdjustmentRoothashMessage
}

Expand Down
17 changes: 15 additions & 2 deletions go/roothash/api/block/header_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package block

import (
"math/big"
"testing"

"github.com/stretchr/testify/require"

"github.com/oasislabs/ekiden/go/common"
"github.com/oasislabs/ekiden/go/common/crypto/hash"
"github.com/oasislabs/ekiden/go/common/crypto/signature"
"github.com/oasislabs/ekiden/go/staking/api"
)

func TestConsistentHash(t *testing.T) {
Expand All @@ -18,14 +21,20 @@ func TestConsistentHash(t *testing.T) {
require.EqualValues(t, emptyHeaderHash, empty.EncodedHash())

var populatedHeaderHash hash.Hash
_ = populatedHeaderHash.UnmarshalHex("036e67a988b0ea6371a4482f708138322c3f7c4dd4ae4610e4018f96d78e1153")
_ = populatedHeaderHash.UnmarshalHex("480a773c029e57cc9f4c520ae659de28eba69bde92371a0dd0f076725382515e")

var emptyRoot hash.Hash
emptyRoot.Empty()

var ns common.Namespace
_ = ns.UnmarshalBinary(emptyRoot[:])

var account signature.PublicKey
require.NoError(t, account.UnmarshalHex("5555555555555555555555555555555555555555555555555555555555555555"), "PublicKey UnmarshalHex")

var amount api.Quantity
require.NoError(t, amount.FromBigInt(big.NewInt(69376)), "Quantity FromBigInt")

populated := Header{
Version: 42,
Namespace: ns,
Expand All @@ -37,7 +46,11 @@ func TestConsistentHash(t *testing.T) {
StateRoot: emptyRoot,
RoothashMessages: []*RoothashMessage{
{
DummyRoothashMessage: &DummyRoothashMessage{Greeting: "hi"},
StakingGeneralAdjustmentRoothashMessage: &StakingGeneralAdjustmentRoothashMessage{
Account: account,
Op: Increase,
Amount: &amount,
},
},
},
}
Expand Down
12 changes: 1 addition & 11 deletions go/tendermint/apps/staking/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/oasislabs/ekiden/go/common/cbor"
"github.com/oasislabs/ekiden/go/common/crypto/signature"
"github.com/oasislabs/ekiden/go/common/logging"
"github.com/oasislabs/ekiden/go/roothash/api/block"
staking "github.com/oasislabs/ekiden/go/staking/api"
"github.com/oasislabs/ekiden/go/tendermint/abci"
Expand All @@ -25,8 +24,6 @@ var (
stateCommonPool = []byte("staking/common_pool")
stateDebondingInterval = []byte("staking/debonding_interval")
stateAcceptableTransferPeers = []byte("staking/acceptable_transfer_peers")

logger = logging.GetLogger("tendermint/staking")
)

type ledgerEntry struct {
Expand Down Expand Up @@ -319,14 +316,7 @@ func (s *MutableState) isAcceptableTransferPeer(runtimeID signature.PublicKey) (
}

func (s *MutableState) HandleRoothashMessage(runtimeID signature.PublicKey, message *block.RoothashMessage) (error, error) {
if message.DummyRoothashMessage != nil {
logger.Info("dummy message from roothash",
"from_runtime", runtimeID,
"greeting", message.DummyRoothashMessage.Greeting,
)
} else if message.DummyRejectRoothashMessage != nil {
return errors.Errorf("encountered dummy reject message from roothash"), nil
} else if message.StakingGeneralAdjustmentRoothashMessage != nil {
if message.StakingGeneralAdjustmentRoothashMessage != nil {
acceptable, err := s.isAcceptableTransferPeer(runtimeID)
if err != nil {
return nil, errors.Wrap(err, "state corrupted")
Expand Down
15 changes: 8 additions & 7 deletions runtime/src/common/roothash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ pub enum AdjustmentOp {
/// Roothash message.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum RoothashMessage {
DummyRoothashMessage {
greeting: String,
},
StakingGeneralAdjustmentRoothashMessage {
account: PublicKey,
op: AdjustmentOp,
Expand Down Expand Up @@ -119,14 +116,18 @@ mod tests {
previous_hash: empty.encoded_hash(),
io_root: Hash::empty_hash(),
state_root: Hash::empty_hash(),
roothash_messages: Some(vec![RoothashMessage::DummyRoothashMessage {
greeting: "hi".to_owned(),
}]),
roothash_messages: Some(vec![
RoothashMessage::StakingGeneralAdjustmentRoothashMessage {
account: PublicKey(*b"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"),
op: AdjustmentOp::INCREASE,
amount: vec![0x01, 0x0f, 0x00],
},
]),
..Default::default()
};
assert_eq!(
populated.encoded_hash(),
Hash::from("036e67a988b0ea6371a4482f708138322c3f7c4dd4ae4610e4018f96d78e1153")
Hash::from("480a773c029e57cc9f4c520ae659de28eba69bde92371a0dd0f076725382515e")
);
}
}

0 comments on commit 45dbf40

Please sign in to comment.