Skip to content

Commit

Permalink
only allow new snapshot with common encoding version
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Oct 3, 2022
1 parent 38dc676 commit 2358988
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kernel/cosi.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (chain *Chain) checkActionSanity(m *CosiAction) error {
if s == nil {
return fmt.Errorf("no snapshot in cosi")
}
if s.Version != common.SnapshotVersionMsgpackEncoding && s.Version != common.SnapshotVersionCommonEncoding {
if s.Version != common.SnapshotVersionCommonEncoding {
return fmt.Errorf("invalid snapshot version %d", s.Version)
}
if s.NodeId != chain.ChainId {
Expand Down
4 changes: 2 additions & 2 deletions kernel/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (node *Node) tryToSendRemoveTransaction() error {
}
chain := node.getOrCreateChain(node.IdForNetwork)
s := &common.Snapshot{
Version: chain.node.SnapshotVersion(),
Version: common.SnapshotVersionCommonEncoding,
NodeId: node.IdForNetwork,
}
s.AddSoleTransaction(tx.PayloadHash())
Expand Down Expand Up @@ -327,7 +327,7 @@ func (chain *Chain) tryToSendAcceptTransaction() error {
return err
}
s := &common.Snapshot{
Version: chain.node.SnapshotVersion(),
Version: common.SnapshotVersionCommonEncoding,
NodeId: chain.ChainId,
}
s.AddSoleTransaction(ver.PayloadHash())
Expand Down
2 changes: 1 addition & 1 deletion kernel/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (node *Node) tryToMintKernelNode() error {
return err
}
s := &common.Snapshot{
Version: node.SnapshotVersion(),
Version: common.SnapshotVersionCommonEncoding,
NodeId: node.IdForNetwork,
}
s.AddSoleTransaction(signed.PayloadHash())
Expand Down
2 changes: 1 addition & 1 deletion kernel/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ func (node *Node) LoadConsensusNodes() error {
return nil
}

// FIXME remove this after all nodes upgraded
func (node *Node) SnapshotVersion() uint8 {
if node.networkId.String() != config.MainnetId {
return common.SnapshotVersionCommonEncoding
Expand All @@ -332,6 +331,7 @@ func (node *Node) SnapshotVersion() uint8 {
return common.SnapshotVersionMsgpackEncoding
}

// this is needed to handle mainnet transaction version upgrading fork
func (node *Node) NewTransaction(assetId crypto.Hash) *common.Transaction {
if node.SnapshotVersion() < common.SnapshotVersionCommonEncoding {
return common.NewTransactionV2(assetId)
Expand Down
6 changes: 3 additions & 3 deletions kernel/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (node *Node) QueueTransaction(tx *common.VersionedTransaction) (string, err
return "", err
}
s := &common.Snapshot{
Version: node.SnapshotVersion(),
Version: common.SnapshotVersionCommonEncoding,
NodeId: node.IdForNetwork,
}
s.AddSoleTransaction(tx.PayloadHash())
Expand Down Expand Up @@ -84,7 +84,7 @@ func (node *Node) LoopCacheQueue() error {
nbor := neighbors[int(clock.Now().UnixNano())%len(neighbors)]
node.SendTransactionToPeer(nbor.IdForNetwork, hash)
s := &common.Snapshot{
Version: node.SnapshotVersion(),
Version: common.SnapshotVersionCommonEncoding,
NodeId: node.IdForNetwork,
}
s.AddSoleTransaction(tx.PayloadHash())
Expand Down Expand Up @@ -129,7 +129,7 @@ func (chain *Chain) clearAndQueueSnapshotOrPanic(s *common.Snapshot) error {
panic("should never be here")
}
ns := &common.Snapshot{
Version: chain.node.SnapshotVersion(),
Version: common.SnapshotVersionCommonEncoding,
NodeId: s.NodeId,
}
ns.AddSoleTransaction(s.SoleTransaction())
Expand Down

0 comments on commit 2358988

Please sign in to comment.