Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into add-identity-on-delegation-view
Browse files Browse the repository at this point in the history
  • Loading branch information
Benzbeeb authored Jul 20, 2020
2 parents 345401d + 0361e84 commit 70d3368
Show file tree
Hide file tree
Showing 73 changed files with 24,593 additions and 22,901 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@

### Chain (Consensus)

- (bugs) [\#2251](https://github.com/bandprotocol/bandchain/pull/2251) go-owasm: Allow OEI to read nil external data

### Chain (Non-consensus)

- (impv) [\#2232](https://github.com/bandprotocol/bandchain/pull/2218) CLI/REST for query active oracle validators.

### Yoda

- (impv) [\#2247](https://github.com/bandprotocol/bandchain/pull/2247) Use max data size configurations from oracle module
- (impv) [\#2249](https://github.com/bandprotocol/bandchain/pull/2249) docker: Run test program during initialization.
- (feat) [\#2218](https://github.com/bandprotocol/bandchain/pull/2218) Implement MultiExec to combine multiple executors.

### Emitter & Flusher

- (feat) [\#2248](https://github.com/bandprotocol/bandchain/pull/2248) Add identity column on delegation view table.
- (bugs) [\#2273](https://github.com/bandprotocol/bandchain/pull/2273) Fix bug update delegators table after withdraw reward.
- (bugs) [\#2255](https://github.com/bandprotocol/bandchain/pull/2255) Fix bug `reward_amount` and `commission_amount` in extra field.
- (bugs) [\#2252](https://github.com/bandprotocol/bandchain/pull/2252) `handle_set_validator` get wrong validator id.
- (impv) [\#2250](https://github.com/bandprotocol/bandchain/pull/2250) Add account id in `validators` table.
- (feat) [\#2246](https://github.com/bandprotocol/bandchain/pull/2246) Implement handle all resolve proposal status.
- (feat) [\#2242](https://github.com/bandprotocol/bandchain/pull/2242) Implement handle MsgVote for emitter and flusher.
Expand All @@ -31,8 +37,15 @@

### Scan

- (impv) [\#2199](https://github.com/bandprotocol/bandchain/pull/2199) Remove proposed blocks count & adjust ui
- (impv) [\#2245](https://github.com/bandprotocol/bandchain/pull/2245) Added more features and patch for guanyu testnet
- (impv) [\#2237](https://github.com/bandprotocol/bandchain/pull/2237/files) Add validator's oracle status.
- (bugs) [\#2236](https://github.com/bandprotocol/bandchain/pull/2236) Fixed uptime query on ValidatorIndexPage
- (impv) [\#2235](https://github.com/bandprotocol/bandchain/pull/2235) added `unbonding` and `redelegate` tabs to account index page.
- (impv) [\#2234](https://github.com/bandprotocol/bandchain/pull/2234) Added support for `received` transaction on scan
- (impv) [\#2228](https://github.com/bandprotocol/bandchain/pull/2228) Add `expired` request status to Scan
- (impv) [\#2203](https://github.com/bandprotocol/bandchain/pull/2203/files) Patch request, report subscription for new cacher.
- (impv) [\#2199](https://github.com/bandprotocol/bandchain/pull/2199) Remove proposed blocks count & adjust ui
- (impv) [\#2176](https://github.com/bandprotocol/bandchain/pull/2176/files) Fixed delegations/unbonding subs, avg blocktime and validator uptime to work with new cacher.

### Bridges

Expand Down
5 changes: 3 additions & 2 deletions chain/emitter/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (app *App) handleMsgWithdrawDelegatorReward(
withdrawAddr := app.DistrKeeper.GetDelegatorWithdrawAddr(app.DeliverContext, msg.DelegatorAddress)
app.AddAccountsInTx(withdrawAddr)
app.emitUpdateValidatorReward(msg.ValidatorAddress)
extra["reward_amount"] = evMap[dist.EventTypeWithdrawRewards+"."+sdk.AttributeKeyAmount]
app.emitDelegationAfterWithdrawReward(msg.ValidatorAddress, withdrawAddr)
extra["reward_amount"] = evMap[dist.EventTypeWithdrawRewards+"."+sdk.AttributeKeyAmount][0]
}

// handleMsgSetWithdrawAddress implements emitter handler for MsgSetWithdrawAddress.
Expand All @@ -56,5 +57,5 @@ func (app *App) handleMsgWithdrawValidatorCommission(
withdrawAddr := app.DistrKeeper.GetDelegatorWithdrawAddr(app.DeliverContext, sdk.AccAddress(msg.ValidatorAddress))
app.AddAccountsInTx(withdrawAddr)
app.emitUpdateValidatorReward(msg.ValidatorAddress)
extra["commission_amount"] = evMap[types.EventTypeWithdrawCommission+"."+sdk.AttributeKeyAmount]
extra["commission_amount"] = evMap[types.EventTypeWithdrawCommission+"."+sdk.AttributeKeyAmount][0]
}
9 changes: 9 additions & 0 deletions chain/emitter/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func (app *App) emitUpdateValidatorStatus(addr sdk.ValAddress) {
})
}

func (app *App) emitDelegationAfterWithdrawReward(operatorAddress sdk.ValAddress, delegatorAddress sdk.AccAddress) {
_, ratio := app.getCurrentRewardAndCurrentRatio(operatorAddress)
app.Write("UPDATE_DELEGATION", JsDict{
"delegator_address": delegatorAddress,
"operator_address": operatorAddress,
"last_ratio": ratio,
})
}

func (app *App) emitDelegation(operatorAddress sdk.ValAddress, delegatorAddress sdk.AccAddress) {
delegation, found := app.StakingKeeper.GetDelegation(app.DeliverContext, delegatorAddress, operatorAddress)
if found {
Expand Down
49 changes: 48 additions & 1 deletion chain/x/oracle/keeper/owasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestResolveRequestSuccessComplex(t *testing.T) {
_, ctx, k := testapp.CreateTestInput(true)
ctx = ctx.WithBlockTime(testapp.ParseTime(1581589890))
k.SetRequest(ctx, 42, types.NewRequest(
// 4st Wasm. Append all reports from all validators.
// 4th Wasm. Append all reports from all validators.
4, obi.MustEncode(testapp.Wasm4Input{
IDs: []int64{1, 2},
Calldata: string(BasicCalldata),
Expand Down Expand Up @@ -313,6 +313,53 @@ func TestResolveRequestSuccessComplex(t *testing.T) {
)}, ctx.EventManager().Events())
}

func TestResolveReadNilExternalData(t *testing.T) {
_, ctx, k := testapp.CreateTestInput(true)
ctx = ctx.WithBlockTime(testapp.ParseTime(1581589890))
k.SetRequest(ctx, 42, types.NewRequest(
// 4th Wasm. Append all reports from all validators.
4, obi.MustEncode(testapp.Wasm4Input{
IDs: []int64{1, 2},
Calldata: string(BasicCalldata),
}), []sdk.ValAddress{testapp.Validator1.ValAddress, testapp.Validator2.ValAddress}, 1,
42, testapp.ParseTime(1581589790), BasicClientID, []types.RawRequest{
types.NewRawRequest(0, 1, BasicCalldata),
types.NewRawRequest(1, 2, BasicCalldata),
},
))
k.SetReport(ctx, 42, types.NewReport(
testapp.Validator1.ValAddress, true, []types.RawReport{
types.NewRawReport(0, 0, nil),
types.NewRawReport(1, 0, []byte("beebd2v1")),
},
))
k.SetReport(ctx, 42, types.NewReport(
testapp.Validator2.ValAddress, true, []types.RawReport{
types.NewRawReport(0, 0, []byte("beebd1v2")),
types.NewRawReport(1, 0, nil),
},
))
k.ResolveRequest(ctx, 42)
reqPacket := types.NewOracleRequestPacketData(
BasicClientID, 4, obi.MustEncode(testapp.Wasm4Input{
IDs: []int64{1, 2},
Calldata: string(BasicCalldata),
}), 2, 1,
)
resPacket := types.NewOracleResponsePacketData(
BasicClientID, 42, 2, testapp.ParseTime(1581589790).Unix(),
testapp.ParseTime(1581589890).Unix(), types.ResolveStatus_Success,
obi.MustEncode(testapp.Wasm4Output{Ret: "beebd1v2beebd2v1"}),
)
require.Equal(t, types.NewResult(reqPacket, resPacket), k.MustGetResult(ctx, 42))
require.Equal(t, sdk.Events{sdk.NewEvent(
types.EventTypeResolve,
sdk.NewAttribute(types.AttributeKeyID, "42"),
sdk.NewAttribute(types.AttributeKeyResolveStatus, "1"),
sdk.NewAttribute(types.AttributeKeyResult, "0000001062656562643176326265656264327631"),
)}, ctx.EventManager().Events())
}

func TestResolveRequestNoReturnData(t *testing.T) {
_, ctx, k := testapp.CreateTestInput(true)
ctx = ctx.WithBlockTime(testapp.ParseTime(1581589890))
Expand Down
6 changes: 2 additions & 4 deletions chain/yoda/executor/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import (
"path/filepath"
"time"

"github.com/bandprotocol/bandchain/chain/x/oracle/types"
"github.com/google/shlex"
)

// TODO: Make this configurable
const MAX_OUTPUT_SIZE = 512

type DockerExec struct {
image string
}
Expand Down Expand Up @@ -79,7 +77,7 @@ func (e *DockerExec) Exec(timeout time.Duration, code []byte, arg string) (ExecR
return ExecResult{}, err
}
}
output, err := ioutil.ReadAll(io.LimitReader(&buf, MAX_OUTPUT_SIZE))
output, err := ioutil.ReadAll(io.LimitReader(&buf, types.MaxDataSize))
if err != nil {
return ExecResult{}, err
}
Expand Down
9 changes: 9 additions & 0 deletions chain/yoda/executor/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ func TestDockerSuccess(t *testing.T) {
// fmt.Println(string(res.Output), res.Code, err)
// require.True(t, false)
}

func TestDockerLongStdout(t *testing.T) {
// TODO: Enable test when CI has docker installed.
// e := NewDockerExec("bandprotocol/runtime:1.0.1")
// res, err := e.Exec(10*time.Second, []byte(`#!/usr/bin/env python3
// print("A"*1000)`), "BTC")
// fmt.Println(string(res.Output), res.Code, err)
// require.True(t, false)
}
12 changes: 11 additions & 1 deletion flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def handle_new_raw_report(self, msg):
def handle_set_validator(self, msg):
msg["account_id"] = self.get_account_id(msg["delegator_address"])
del msg["delegator_address"]
if self.get_account_id(msg["operator_address"]) is None:
if self.get_validator_id(msg["operator_address"]) is None:
self.conn.execute(validators.insert(), msg)
else:
condition = True
Expand All @@ -154,6 +154,16 @@ def handle_set_delegation(self, msg):
.on_conflict_do_update(constraint="delegations_pkey", set_=msg)
)

def handle_update_delegation(self, msg):
msg["delegator_id"] = self.get_account_id(msg["delegator_address"])
del msg["delegator_address"]
msg["validator_id"] = self.get_validator_id(msg["operator_address"])
del msg["operator_address"]
condition = True
for col in delegations.primary_key.columns.values():
condition = (col == msg[col.name]) & condition
self.conn.execute(delegations.update().where(condition).values(**msg))

def handle_remove_delegation(self, msg):
msg["delegator_id"] = self.get_account_id(msg["delegator_address"])
del msg["delegator_address"]
Expand Down
3 changes: 0 additions & 3 deletions go-owasm/api/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,5 @@ func cGetExternalData(e *C.env_t, eid C.int64_t, vid C.int64_t, data *C.Span) C.
if err != nil {
return toCError(err)
}
if extData == nil {
return C.Error_UnavailableExternalDataError
}
return writeSpan(data, extData)
}
Loading

0 comments on commit 70d3368

Please sign in to comment.