mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
remove unnecessary bidirectional features
This commit is contained in:
parent
b147232be7
commit
ec105e88ad
@ -12,8 +12,8 @@ Simplifications:
|
|||||||
- refactor queue into one object
|
- refactor queue into one object
|
||||||
- Do all the small functions need to be methods on the keeper or can they just be floating around?
|
- Do all the small functions need to be methods on the keeper or can they just be floating around?
|
||||||
- Tidy up - standardise var names, method descriptions, heading comments
|
- Tidy up - standardise var names, method descriptions, heading comments
|
||||||
- is having all the get functions return a bool if not found reasonable?
|
|
||||||
- any problem in signing your own address?
|
- any problem in signing your own address?
|
||||||
- Gas
|
- Gas
|
||||||
- Codespace
|
- Codespace
|
||||||
- find nicer name for payouts
|
- find nicer name for payouts
|
||||||
|
- tags - return channel id
|
||||||
|
@ -31,7 +31,6 @@ func TestEndBlocker(t *testing.T) {
|
|||||||
update := Update{
|
update := Update{
|
||||||
ChannelID: channelID,
|
ChannelID: channelID,
|
||||||
Payouts: payouts,
|
Payouts: payouts,
|
||||||
Sequence: 0,
|
|
||||||
Sigs: [1]crypto.Signature{},
|
Sigs: [1]crypto.Signature{},
|
||||||
}
|
}
|
||||||
sUpdate := SubmittedUpdate{
|
sUpdate := SubmittedUpdate{
|
||||||
|
@ -97,11 +97,18 @@ func (k Keeper) InitCloseChannelBySender(ctx sdk.Context, update Update) (sdk.Ta
|
|||||||
}
|
}
|
||||||
if q.Contains(update.ChannelID) {
|
if q.Contains(update.ChannelID) {
|
||||||
// Someone has previously tried to update channel
|
// Someone has previously tried to update channel
|
||||||
existingSUpdate, found := k.getSubmittedUpdate(ctx, update.ChannelID)
|
// In bidirectional channels the new update is compared against existing and replaces it if it has a higher sequence number.
|
||||||
if !found {
|
|
||||||
panic("can't find element in queue that should exist")
|
// existingSUpdate, found := k.getSubmittedUpdate(ctx, update.ChannelID)
|
||||||
}
|
// if !found {
|
||||||
k.addToSubmittedUpdatesQueue(ctx, k.applyNewUpdate(existingSUpdate, update))
|
// panic("can't find element in queue that should exist")
|
||||||
|
// }
|
||||||
|
// k.addToSubmittedUpdatesQueue(ctx, k.applyNewUpdate(existingSUpdate, update))
|
||||||
|
|
||||||
|
// However in unidirectional case, only the sender can close a channel this way. No clear need for them to be able to submit an update replacing a previous one they sent, so don't allow it.
|
||||||
|
// TODO tags
|
||||||
|
// TODO custom errors return sdk.EmptyTags(), sdk.NewError("Sender can't submit an update for channel if one has already been submitted.")
|
||||||
|
panic("Sender can't submit an update for channel if one has already been submitted.")
|
||||||
} else {
|
} else {
|
||||||
// No one has tried to update channel
|
// No one has tried to update channel
|
||||||
submittedUpdate := SubmittedUpdate{
|
submittedUpdate := SubmittedUpdate{
|
||||||
@ -136,21 +143,22 @@ func (k Keeper) CloseChannelByReceiver(ctx sdk.Context, update Update) (sdk.Tags
|
|||||||
|
|
||||||
// Main function that compare updates against each other.
|
// Main function that compare updates against each other.
|
||||||
// Pure function
|
// Pure function
|
||||||
func (k Keeper) applyNewUpdate(existingSUpdate SubmittedUpdate, proposedUpdate Update) SubmittedUpdate {
|
// Not needed in unidirectional case.
|
||||||
var returnUpdate SubmittedUpdate
|
// func (k Keeper) applyNewUpdate(existingSUpdate SubmittedUpdate, proposedUpdate Update) SubmittedUpdate {
|
||||||
|
// var returnUpdate SubmittedUpdate
|
||||||
|
|
||||||
if existingSUpdate.Sequence > proposedUpdate.Sequence {
|
// if existingSUpdate.Sequence > proposedUpdate.Sequence {
|
||||||
// update accepted
|
// // update accepted
|
||||||
returnUpdate = SubmittedUpdate{
|
// returnUpdate = SubmittedUpdate{
|
||||||
Update: proposedUpdate,
|
// Update: proposedUpdate,
|
||||||
ExecutionTime: existingSUpdate.ExecutionTime,
|
// ExecutionTime: existingSUpdate.ExecutionTime, // FIXME any new update proposal should be subject to full dispute period from submission
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
// update rejected
|
// // update rejected
|
||||||
returnUpdate = existingSUpdate
|
// returnUpdate = existingSUpdate
|
||||||
}
|
// }
|
||||||
return returnUpdate
|
// return returnUpdate
|
||||||
}
|
// }
|
||||||
|
|
||||||
// unsafe close channel - doesn't check if update matches existing channel TODO make safer?
|
// unsafe close channel - doesn't check if update matches existing channel TODO make safer?
|
||||||
func (k Keeper) closeChannel(ctx sdk.Context, update Update) (sdk.Tags, sdk.Error) {
|
func (k Keeper) closeChannel(ctx sdk.Context, update Update) (sdk.Tags, sdk.Error) {
|
||||||
|
@ -70,7 +70,6 @@ func TestKeeper(t *testing.T) {
|
|||||||
update := Update{
|
update := Update{
|
||||||
ChannelID: channelID,
|
ChannelID: channelID,
|
||||||
Payouts: payouts,
|
Payouts: payouts,
|
||||||
Sequence: 0,
|
|
||||||
Sigs: [1]crypto.Signature{},
|
Sigs: [1]crypto.Signature{},
|
||||||
}
|
}
|
||||||
// Set empty submittedUpdatesQueue TODO work out proper genesis initialisation
|
// Set empty submittedUpdatesQueue TODO work out proper genesis initialisation
|
||||||
@ -118,7 +117,6 @@ func TestKeeper(t *testing.T) {
|
|||||||
update := Update{
|
update := Update{
|
||||||
ChannelID: channelID,
|
ChannelID: channelID,
|
||||||
Payouts: payouts,
|
Payouts: payouts,
|
||||||
Sequence: 0,
|
|
||||||
Sigs: [1]crypto.Signature{},
|
Sigs: [1]crypto.Signature{},
|
||||||
}
|
}
|
||||||
// Set empty submittedUpdatesQueue TODO work out proper genesis initialisation
|
// Set empty submittedUpdatesQueue TODO work out proper genesis initialisation
|
||||||
|
@ -23,8 +23,8 @@ type ChannelID int64 // TODO should this be positive only
|
|||||||
type Update struct {
|
type Update struct {
|
||||||
ChannelID ChannelID
|
ChannelID ChannelID
|
||||||
Payouts Payouts //map[string]sdk.Coins // map of bech32 addresses to coins
|
Payouts Payouts //map[string]sdk.Coins // map of bech32 addresses to coins
|
||||||
Sequence int64
|
//Sequence int64 Not needed for unidirectional channels
|
||||||
Sigs [1]crypto.Signature // only sender needs to sign
|
Sigs [1]crypto.Signature // only sender needs to sign in unidirectional
|
||||||
}
|
}
|
||||||
type Payout struct {
|
type Payout struct {
|
||||||
Address sdk.AccAddress
|
Address sdk.AccAddress
|
||||||
|
Loading…
Reference in New Issue
Block a user