// Executes block's transactions on proxyAppConn. // TODO: Generate a bitmap or otherwise store tx validity in state. func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy.AppConn, block *types.Block) error { var validTxs, invalidTxs = 0, 0 // Execute transactions and get hash proxyCb := func(req *tmsp.Request, res *tmsp.Response) { switch res.Type { case tmsp.MessageType_AppendTx: // TODO: make use of res.Log // TODO: make use of this info // Blocks may include invalid txs. // reqAppendTx := req.(tmsp.RequestAppendTx) if res.Code == tmsp.CodeType_OK { validTxs += 1 } else { log.Debug("Invalid tx", "code", res.Code, "log", res.Log) invalidTxs += 1 } } } proxyAppConn.SetResponseCallback(proxyCb) // Run next txs in the block and get new AppHash for _, tx := range block.Txs { proxyAppConn.AppendTxAsync(tx) if err := proxyAppConn.Error(); err != nil { return err } } hash, logStr, err := proxyAppConn.GetHashSync() if err != nil { log.Warn("Error computing proxyAppConn hash", "error", err) return err } if logStr != "" { log.Debug("GetHash.Log: " + logStr) } log.Info(Fmt("ExecBlock got %v valid txs and %v invalid txs", validTxs, invalidTxs)) // Set the state's new AppHash s.AppHash = hash return nil }
// Executes block's transactions on proxyAppConn. // TODO: Generate a bitmap or otherwise store tx validity in state. func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy.AppConn, block *types.Block) error { var validTxs, invalidTxs = 0, 0 // Execute transactions and get hash proxyCb := func(req tmsp.Request, res tmsp.Response) { switch res := res.(type) { case tmsp.ResponseAppendTx: // TODO: make use of this info // Blocks may include invalid txs. // reqAppendTx := req.(tmsp.RequestAppendTx) if res.RetCode == tmsp.RetCodeOK { validTxs += 1 } else { invalidTxs += 1 } case tmsp.ResponseEvent: // TODO: some events should get stored in the blockchain. evsw.FireEvent(types.EventStringApp(), types.EventDataApp{res.Key, res.Data}) } } proxyAppConn.SetResponseCallback(proxyCb) // Run next txs in the block and get new AppHash for _, tx := range block.Txs { proxyAppConn.AppendTxAsync(tx) if err := proxyAppConn.Error(); err != nil { return err } } hash, err := proxyAppConn.GetHashSync() if err != nil { log.Warn("Error computing proxyAppConn hash", "error", err) return err } log.Info(Fmt("ExecBlock got %v valid txs and %v invalid txs", validTxs, invalidTxs)) // Set the state's new AppHash s.AppHash = hash return nil }
// Executes block's transactions on proxyAppConn. // TODO: Generate a bitmap or otherwise store tx validity in state. func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy.AppConn, block *types.Block) error { var validTxs, invalidTxs = 0, 0 // Execute transactions and get hash proxyCb := func(req *tmsp.Request, res *tmsp.Response) { switch res.Type { case tmsp.MessageType_AppendTx: // TODO: make use of res.Log // TODO: make use of this info // Blocks may include invalid txs. // reqAppendTx := req.(tmsp.RequestAppendTx) if res.Code == tmsp.CodeType_OK { validTxs += 1 } else { log.Debug("Invalid tx", "code", res.Code, "log", res.Log) invalidTxs += 1 } } } proxyAppConn.SetResponseCallback(proxyCb) // Run txs of block for _, tx := range block.Txs { proxyAppConn.AppendTxAsync(tx) if err := proxyAppConn.Error(); err != nil { return err } } // End block changedValidators, err := proxyAppConn.EndBlockSync(uint64(block.Height)) if err != nil { log.Warn("Error in proxyAppConn.EndBlock", "error", err) return err } // TODO: Do something with changedValidators log.Info("TODO: Do something with changedValidators", changedValidators) log.Info(Fmt("ExecBlock got %v valid txs and %v invalid txs", validTxs, invalidTxs)) return nil }